mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-12 09:09:25 +00:00
Added i18n messages to mw.msg fallback
Change-Id: Ic4b44eb6ab31392fa727f14ec38800fe6b185d44
This commit is contained in:
parent
39dc10d1d8
commit
44d50c980f
|
@ -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>
|
||||
|
|
|
@ -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 = {};
|
||||
|
|
Loading…
Reference in a new issue