X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fjquery%2Fjquery.localize.js;h=d9a2b199f39246e79b6522fce97eb1fc1f1e36f7;hb=b4ee5c38b56237f80e892e27cd7cabad5aa679d8;hp=866778f879bfcc6c5a62c463cd6fe6063a32bd74;hpb=eeb7300f6004e95620514eb9bac508425e94f197;p=lhc%2Fweb%2Fwiklou.git
diff --git a/resources/jquery/jquery.localize.js b/resources/jquery/jquery.localize.js
index 866778f879..d9a2b199f3 100644
--- a/resources/jquery/jquery.localize.js
+++ b/resources/jquery/jquery.localize.js
@@ -1,9 +1,31 @@
/**
- * Simple Placeholder-based Localization
+ * @class jQuery.plugin.localize
+ */
+( function ( $, mw ) {
+
+/**
+ * Gets a localized message, using parameters from options if present.
+ * @ignore
+ *
+ * @param {Object} options
+ * @param {string} key
+ * @returns {string} Localized message
+ */
+function msg( options, key ) {
+ var args = options.params[key] || [];
+ // Format: mw.msg( key [, p1, p2, ...] )
+ args.unshift( options.prefix + ( options.keys[key] || key ) );
+ return mw.msg.apply( mw, args );
+}
+
+/**
+ * Localizes a DOM selection by replacing elements with localized text and adding
+ * localized title and alt attributes to elements with title-msg and alt-msg attributes
+ * respectively.
*
- * Call on a selection of HTML which contains elements or elements
+ * Call on a selection of HTML which contains `` elements or elements
* with title-msg="message-key", alt-msg="message-key" or placeholder-msg="message-key" attributes.
- * elements will be replaced with localized text, *-msg attributes will be replaced
+ * `` elements will be replaced with localized text, *-msg attributes will be replaced
* with attributes that do not have the "-msg" suffix and contain a localized message.
*
* Example:
@@ -77,34 +99,12 @@
* Appends something like this to the body...
*
You may not get there all in one piece.
*
- */
-( function ( $, mw ) {
-
-/**
- * Gets a localized message, using parameters from options if present.
- *
- * @function
- * @param {String} key Message key to get localized message for
- * @returns {String} Localized message
- */
-function msg( options, key ) {
- var args = options.params[key] || [];
- // Format: mw.msg( key [, p1, p2, ...] )
- args.unshift( options.prefix + ( options.keys[key] || key ) );
- return mw.msg.apply( mw, args );
-}
-
-/**
- * Localizes a DOM selection by replacing elements with localized text and adding
- * localized title and alt attributes to elements with title-msg and alt-msg attributes
- * respectively.
- *
* @method
* @param {Object} options Map of options to be used while localizing
- * @param {String} options.prefix String to prepend to all message keys
+ * @param {string} options.prefix String to prepend to all message keys
* @param {Object} options.keys Message key aliases, used for remapping keys to a template
* @param {Object} options.params Lists of parameters to use with certain message keys
- * @returns {jQuery} This selection
+ * @return {jQuery}
*/
$.fn.localize = function ( options ) {
var $target = this,
@@ -145,10 +145,26 @@ $.fn.localize = function ( options ) {
} );
} );
+ // HTML, Text for elements which cannot have children e.g. OPTION
+ $target.find( '[data-msg-text]' ).each( function() {
+ var $el = $( this );
+ $el.text( msg( options, $el.attr( 'data-msg-text' ) ) );
+ } );
+
+ $target.find( '[data-msg-html]' ).each( function() {
+ var $el = $( this );
+ $el.html( msg( options, $el.attr( 'data-msg-html' ) ) );
+ } );
+
return $target;
};
// Let IE know about the msg tag before it's used...
document.createElement( 'msg' );
+/**
+ * @class jQuery
+ * @mixins jQuery.plugin.localize
+ */
+
}( jQuery, mediaWiki ) );