Added i18n messages to mw.msg fallback

Change-Id: Ic4b44eb6ab31392fa727f14ec38800fe6b185d44
This commit is contained in:
Trevor Parscal 2012-06-19 13:58:54 -07:00
parent 39dc10d1d8
commit 44d50c980f
2 changed files with 25 additions and 1 deletions

View file

@ -89,6 +89,12 @@ include( '../../modules/sandbox/base.php' );
<script src="../../modules/jquery/jquery.js"></script>
<script src="../../modules/jquery/jquery.json.js"></script>
<script src="../../modules/ve2/ve.js"></script>
<script>
<?php
include( dirname( dirname( dirname( __FILE__ ) ) ) . '/VisualEditor.i18n.php' );
echo 've.msg.messages = ' . json_encode( $messages['en'] );
?>
</script>
<script src="../../modules/ve2/ve.debug.js"></script>
<script src="../../modules/ve2/ve.EventEmitter.js"></script>
<script src="../../modules/ve2/ve.Factory.js"></script>

View file

@ -335,11 +335,29 @@ ve.debounce = function( func, wait, immediate ) {
/**
* Gets a localized message.
*
* If mw.msg isn't available, a basic implementation is used instead.
*
* @static
* @method
* @param {String} key Message key
* @param {Mixed} [...] Message parameters
*/
ve.msg = typeof mw === 'object' ? mw.msg : function( key ) {
return '(' + key + ')';
if ( key in ve.msg.messages ) {
// Simple message parser, does $N replacement and nothing else.
var parameters = Array.prototype.slice.call( arguments, 0 );
return ve.msg.messages[key].replace( /\$(\d+)/g, function ( str, match ) {
var index = parseInt( match, 10 ) - 1;
return parameters[index] !== undefined ? parameters[index] : '$' + match;
} );
}
return '<' + key + '>';
};
/**
* Map of message keys and values used by the mw.msg fallback.
*
* @static
* @member
*/
ve.msg.messages = {};