r86435 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86434‎ | r86435 | r86436 >
Date:21:01, 19 April 2011
Author:tparscal
Status:ok
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/resources/jquery/jquery.localize.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.localize.js
@@ -32,13 +32,16 @@
3333 */
3434
3535 $.fn.localize = function( options ) {
36 - options = $.extend( { 'prefix': '' }, options );
 36+ options = $.extend( { 'prefix': '', 'keys': {} }, options );
 37+ function msg( key ) {
 38+ return mw.msg( options.prefix + ( key in options.keys ? options.keys[key] : key ) )
 39+ };
3740 return $(this)
3841 .find( 'msg,html\\:msg' )
3942 .each( function() {
4043 var $el = $(this);
4144 $el
42 - .text( mw.msg( options.prefix + $el.attr( 'key' ) ) )
 45+ .text( msg( $el.attr( 'key' ) ) )
4346 .replaceWith( $el.html() );
4447 } )
4548 .end()
@@ -46,7 +49,7 @@
4750 .each( function() {
4851 var $el = $(this);
4952 $el
50 - .attr( 'title', mw.msg( options.prefix + $el.attr( 'title-msg' ) ) )
 53+ .attr( 'title', msg( $el.attr( 'title-msg' ) ) )
5154 .removeAttr( 'title-msg' );
5255 } )
5356 .end()
@@ -54,7 +57,7 @@
5558 .each( function() {
5659 var $el = $(this);
5760 $el
58 - .attr( 'alt', mw.msg( options.prefix + $el.attr( 'alt-msg' ) ) )
 61+ .attr( 'alt', msg( $el.attr( 'alt-msg' ) ) )
5962 .removeAttr( 'alt-msg' );
6063 } )
6164 .end();

Status & tagging log