For I35e55658 in VisualEditor.
Change-Id: I5d894f8a1cba65a3d90dfbf3e43be4e515a327d1
'mediawiki.cldr',
),
'targets' => array( 'desktop', 'mobile' ),
+ 'messages' => array(
+ 'and',
+ 'comma-separator',
+ 'word-separator'
+ ),
),
'mediawiki.cldr' => array(
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 ) );
grammarTest( langCode, test );
}
} );
+
+ QUnit.test( 'List to text test', 4, function ( assert ) {
+ assert.equal( mw.language.listToText( [] ), '', 'Blank list' );
+ assert.equal( mw.language.listToText( ['a'] ), 'a', 'Single item' );
+ assert.equal( mw.language.listToText( ['a', 'b'] ), 'a and b', 'Two items' );
+ assert.equal( mw.language.listToText( ['a', 'b', 'c'] ), 'a, b and c', 'More than two items' );
+ } );
}( mediaWiki, jQuery ) );