From 90d5d3568047f44a704d70c7a798b0a2c0049b0b Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Tue, 19 Apr 2011 21:01:01 +0000 Subject: [PATCH] Added keys option to jquery.localize, allowing message keys to be remapped when rendering a template by providing a an object of [message-key-in-template]/[message-key-to-use] pairs. --- resources/jquery/jquery.localize.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/resources/jquery/jquery.localize.js b/resources/jquery/jquery.localize.js index 15e0164955..56e82d2704 100644 --- a/resources/jquery/jquery.localize.js +++ b/resources/jquery/jquery.localize.js @@ -32,13 +32,16 @@ */ $.fn.localize = function( options ) { - options = $.extend( { 'prefix': '' }, options ); + options = $.extend( { 'prefix': '', 'keys': {} }, options ); + function msg( key ) { + return mw.msg( options.prefix + ( key in options.keys ? options.keys[key] : key ) ) + }; return $(this) .find( 'msg,html\\:msg' ) .each( function() { var $el = $(this); $el - .text( mw.msg( options.prefix + $el.attr( 'key' ) ) ) + .text( msg( $el.attr( 'key' ) ) ) .replaceWith( $el.html() ); } ) .end() @@ -46,7 +49,7 @@ $.fn.localize = function( options ) { .each( function() { var $el = $(this); $el - .attr( 'title', mw.msg( options.prefix + $el.attr( 'title-msg' ) ) ) + .attr( 'title', msg( $el.attr( 'title-msg' ) ) ) .removeAttr( 'title-msg' ); } ) .end() @@ -54,7 +57,7 @@ $.fn.localize = function( options ) { .each( function() { var $el = $(this); $el - .attr( 'alt', mw.msg( options.prefix + $el.attr( 'alt-msg' ) ) ) + .attr( 'alt', msg( $el.attr( 'alt-msg' ) ) ) .removeAttr( 'alt-msg' ); } ) .end(); -- 2.20.1