*
* @param {number} count Non-localized quantifier
* @param {Array} forms List of plural forms
+ * @param {Object} [explicitPluralForms] List of explicit plural forms
* @return {string} Correct form for quantifier in this language
*/
- convertPlural: function ( count, forms ) {
+ convertPlural: function ( count, forms, explicitPluralForms ) {
var pluralRules,
- formCount,
- form,
- index,
- equalsPosition,
pluralFormIndex = 0;
- if ( !forms || forms.length === 0 ) {
- return '';
- }
-
- // Handle for explicit n= forms
- for ( index = 0; index < forms.length; index++ ) {
- form = forms[index];
- if ( /^\d+=/.test( form ) ) {
- equalsPosition = form.indexOf( '=' );
- formCount = parseInt( form.substring( 0, equalsPosition ), 10 );
- if ( formCount === count ) {
- return form.substr( equalsPosition + 1 );
- }
- forms[index] = undefined;
- }
+ if ( explicitPluralForms && explicitPluralForms[count] ) {
+ return explicitPluralForms[count];
}
- // Remove explicit plural forms from the forms.
- forms = $.map( forms, function ( form ) {
- return form;
- } );
-
- if ( forms.length === 0 ) {
+ if ( !forms || forms.length === 0 ) {
return '';
}
return grammarForms[form][word] || word;
}
return word;
- }
+ },
+ /**
+ * Turn a list of string into a simple list using commas and 'and'.
+ *
+ * See Language::listToText in languages/Language.php
+ *
+ * @param {string[]} list
+ * @return {string}
+ */
+ listToText: function ( list ) {
+ var text = '', i = 0;
+ for ( ; i < list.length; i++ ) {
+ text += list[i];
+ if ( list.length - 2 === i ) {
+ text += mw.msg( 'and' ) + mw.msg( 'word-separator' );
+ } else if ( list.length - 1 !== i ) {
+ text += mw.msg( 'comma-separator' );
+ }
+ }
+ return text;
+ }
} );
}( mediaWiki, jQuery ) );