"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "resources/lib/jquery.i18n/src/jquery.i18n.emitter.js" between
mediawiki-1.31.1.tar.gz and mediawiki-1.32.0.tar.gz

About: MediaWiki is a wiki engine (the collaborative editing software that runs for e.g. Wikipedia, the free encyclopedia).

jquery.i18n.emitter.js  (mediawiki-1.31.1):jquery.i18n.emitter.js  (mediawiki-1.32.0)
/** /*!
* jQuery Internationalization library * jQuery Internationalization library
* *
* Copyright (C) 2011-2013 Santhosh Thottingal, Neil Kandalgaonkar * Copyright (C) 2011-2013 Santhosh Thottingal, Neil Kandalgaonkar
* *
* jquery.i18n is dual licensed GPLv2 or later and MIT. You don't have to do * jquery.i18n is dual licensed GPLv2 or later and MIT. You don't have to do
* anything special to choose one license or the other and you don't have to * anything special to choose one license or the other and you don't have to
* notify anyone which license you are using. You are free to use * notify anyone which license you are using. You are free to use
* UniversalLanguageSelector in commercial projects as long as the copyright * UniversalLanguageSelector in commercial projects as long as the copyright
* header is left intact. See files GPL-LICENSE and MIT-LICENSE for details. * header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.
* *
* @licence GNU General Public Licence 2.0 or later * @licence GNU General Public Licence 2.0 or later
* @licence MIT License * @licence MIT License
*/ */
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
var MessageParserEmitter = function () { var MessageParserEmitter = function () {
this.language = $.i18n.languages[String.locale] || $.i18n.languag es['default']; this.language = $.i18n.languages[ String.locale ] || $.i18n.langu ages[ 'default' ];
}; };
MessageParserEmitter.prototype = { MessageParserEmitter.prototype = {
constructor: MessageParserEmitter, constructor: MessageParserEmitter,
/** /**
* (We put this method definition here, and not in prototype, to make * (We put this method definition here, and not in prototype, to make
* sure it's not overwritten by any magic.) Walk entire node stru cture, * sure it's not overwritten by any magic.) Walk entire node stru cture,
* applying replacements and template functions when appropriate * applying replacements and template functions when appropriate
* *
* @param {Mixed} node abstract syntax tree (top node or subnode) * @param {Mixed} node abstract syntax tree (top node or subnode)
* @param {Array} replacements for $1, $2, ... $n * @param {Array} replacements for $1, $2, ... $n
* @return {Mixed} single-string node or array of nodes suitable for * @return {Mixed} single-string node or array of nodes suitable for
* jQuery appending. * jQuery appending.
*/ */
emit: function ( node, replacements ) { emit: function ( node, replacements ) {
var ret, subnodes, operation, var ret, subnodes, operation,
messageParserEmitter = this; messageParserEmitter = this;
switch ( typeof node ) { switch ( typeof node ) {
case 'string': case 'string':
case 'number': case 'number':
ret = node; ret = node;
break; break;
case 'object': case 'object':
// node is an array of nodes // node is an array of nodes
subnodes = $.map( node.slice( 1 ), function ( n ) subnodes = $.map( node.slice( 1 ), functi
{ on ( n ) {
return messageParserEmitter.emit( n, repl return messageParserEmitter.emit(
acements ); n, replacements );
} ); } );
operation = node[0].toLowerCase(); operation = node[ 0 ].toLowerCase();
if ( typeof messageParserEmitter[operation] === ' if ( typeof messageParserEmitter[ operati
function' ) { on ] === 'function' ) {
ret = messageParserEmitter[operation]( su ret = messageParserEmitter[ opera
bnodes, replacements ); tion ]( subnodes, replacements );
} else { } else {
throw new Error( 'unknown operation "' + throw new Error( 'unknown operati
operation + '"' ); on "' + operation + '"' );
} }
break; break;
case 'undefined': case 'undefined':
// Parsing the empty string (as an entire express ion, or as a // Parsing the empty string (as an entire express ion, or as a
// paramExpression in a template) results in unde fined // paramExpression in a template) results in unde fined
// Perhaps a more clever parser can detect this, and return the // Perhaps a more clever parser can detect this, and return the
// empty string? Or is that useful information? // empty string? Or is that useful information?
// The logical thing is probably to return the em pty string here // The logical thing is probably to return the em pty string here
// when we encounter undefined. // when we encounter undefined.
ret = ''; ret = '';
break; break;
default: default:
throw new Error( 'unexpected type in AST: ' + typ throw new Error( 'unexpected type in AST:
eof node ); ' + typeof node );
} }
return ret; return ret;
}, },
/** /**
* Parsing has been applied depth-first we can assume that all no des * Parsing has been applied depth-first we can assume that all no des
* here are single nodes Must return a single node to parents -- a * here are single nodes Must return a single node to parents -- a
* jQuery with synthetic span However, unwrap any other synthetic spans * jQuery with synthetic span However, unwrap any other synthetic spans
* in our children and pass them upwards * in our children and pass them upwards
* *
* @param {Array} nodes Mixed, some single nodes, some arrays of nodes. * @param {Array} nodes Mixed, some single nodes, some arrays of nodes.
* @return String * @return {string}
*/ */
concat: function ( nodes ) { concat: function ( nodes ) {
var result = ''; var result = '';
$.each( nodes, function ( i, node ) { $.each( nodes, function ( i, node ) {
// strings, integers, anything else // strings, integers, anything else
result += node; result += node;
} ); } );
return result; return result;
skipping to change at line 109 skipping to change at line 109
* zero-based. i.e. $1 should have become [ 0 ]. if the specified * zero-based. i.e. $1 should have become [ 0 ]. if the specified
* parameter is not found return the same string (e.g. "$99" -> * parameter is not found return the same string (e.g. "$99" ->
* parameter 98 -> not found -> return "$99" ) TODO throw error i f * parameter 98 -> not found -> return "$99" ) TODO throw error i f
* nodes.length > 1 ? * nodes.length > 1 ?
* *
* @param {Array} nodes One element, integer, n >= 0 * @param {Array} nodes One element, integer, n >= 0
* @param {Array} replacements for $1, $2, ... $n * @param {Array} replacements for $1, $2, ... $n
* @return {string} replacement * @return {string} replacement
*/ */
replace: function ( nodes, replacements ) { replace: function ( nodes, replacements ) {
var index = parseInt( nodes[0], 10 ); var index = parseInt( nodes[ 0 ], 10 );
if ( index < replacements.length ) { if ( index < replacements.length ) {
// replacement is not a string, don't touch! // replacement is not a string, don't touch!
return replacements[index]; return replacements[ index ];
} else { } else {
// index not found, fallback to displaying variab le // index not found, fallback to displaying variab le
return '$' + ( index + 1 ); return '$' + ( index + 1 );
} }
}, },
/** /**
* Transform parsed structure into pluralization n.b. The first n ode may * Transform parsed structure into pluralization n.b. The first n ode may
* be a non-integer (for instance, a string representing an Arabi c * be a non-integer (for instance, a string representing an Arabi c
* number). So convert it back with the current language's * number). So convert it back with the current language's
* convertNumber. * convertNumber.
* *
* @param {Array} nodes List [ {String|Number}, {String}, {String } ... ] * @param {Array} nodes List [ {String|Number}, {String}, {String } ... ]
* @return {String} selected pluralized form according to current * @return {string} selected pluralized form according to current
* language. * language.
*/ */
plural: function ( nodes ) { plural: function ( nodes ) {
var count = parseFloat( this.language.convertNumber( node s[0], 10 ) ), var count = parseFloat( this.language.convertNumber( node s[ 0 ], 10 ) ),
forms = nodes.slice( 1 ); forms = nodes.slice( 1 );
return forms.length ? this.language.convertPlural( count, forms ) : ''; return forms.length ? this.language.convertPlural( count, forms ) : '';
}, },
/** /**
* Transform parsed structure into gender Usage * Transform parsed structure into gender Usage
* {{gender:gender|masculine|feminine|neutral}}. * {{gender:gender|masculine|feminine|neutral}}.
* *
* @param {Array} nodes List [ {String}, {String}, {String} , {St ring} ] * @param {Array} nodes List [ {String}, {String}, {String} , {St ring} ]
* @return {String} selected gender form according to current lan guage * @return {string} selected gender form according to current lan guage
*/ */
gender: function ( nodes ) { gender: function ( nodes ) {
var gender = nodes[0], var gender = nodes[ 0 ],
forms = nodes.slice( 1 ); forms = nodes.slice( 1 );
return this.language.gender( gender, forms ); return this.language.gender( gender, forms );
}, },
/** /**
* Transform parsed structure into grammar conversion. Invoked by * Transform parsed structure into grammar conversion. Invoked by
* putting {{grammar:form|word}} in a message * putting {{grammar:form|word}} in a message
* *
* @param {Array} nodes List [{Grammar case eg: genitive}, {Strin g word}] * @param {Array} nodes List [{Grammar case eg: genitive}, {Strin g word}]
* @return {String} selected grammatical form according to curren t * @return {string} selected grammatical form according to curren t
* language. * language.
*/ */
grammar: function ( nodes ) { grammar: function ( nodes ) {
var form = nodes[0], var form = nodes[ 0 ],
word = nodes[1]; word = nodes[ 1 ];
return word && form && this.language.convertGrammar( word , form ); return word && form && this.language.convertGrammar( word , form );
} }
}; };
$.extend( $.i18n.parser.emitter, new MessageParserEmitter() ); $.extend( $.i18n.parser.emitter, new MessageParserEmitter() );
}( jQuery ) ); }( jQuery ) );
 End of changes. 15 change blocks. 
40 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)