Last modified: 2012-07-11 20:06:48 UTC
In PHP, one can do: global $wgLang; $arr = array( 'Apples', 'Bananas', 'Carrots ); $str = $wgLang->commaList( $arr ); But at the moment one cannot mimic this in JavaScript, even if one has localised the strings themselves already (as in my case).
For most languages arr.join(', ') will work.
(In reply to comment #1) > For most languages arr.join(', ') will work. Yes, but which? :)
MessagesAn.php:'comma-separator' => ', ', MessagesAr.php:'comma-separator' => '، ', MessagesArz.php:'comma-separator' => '، ', MessagesCkb.php:'comma-separator' => '، ', MessagesDiq.php:'comma-separator' => ', ', MessagesEn.php:'comma-separator' => ', ', # only translate this message to other languages if you have to change it MessagesEs.php:'comma-separator' => ', ', MessagesFa.php:'comma-separator' => '، ', MessagesGan_hans.php:'comma-separator' => '、', MessagesGan_hant.php:'comma-separator' => '、', MessagesJa.php:'comma-separator' => '、', MessagesKa.php:'comma-separator' => ', ', MessagesKk_arab.php:'comma-separator' => '، ', MessagesLzh.php:'comma-separator' => '、', MessagesNe.php:'comma-separator' => ', ', MessagesQqq.php:'comma-separator' => '{{optional}}', MessagesRoa_tara.php:'comma-separator' => ', ', MessagesSc.php:'comma-separator' => ', ', MessagesSr_ec.php:'comma-separator' => ', ', MessagesSr_el.php:'comma-separator' => ', ', MessagesUk.php:'comma-separator' => ', ', MessagesWuu.php:'comma-separator' => '、', MessagesYue.php:'comma-separator' => '、', MessagesZh_hans.php:'comma-separator' => '、', MessagesZh_hant.php:'comma-separator' => '、', Looks like it won't work for Gan_hans, Gan_hant, Ja, Lzh, Wuu, Yue, Zh_hans or Zh_hant.
Do the JavaScript bits duplicate PHP descriptions though, or load on top of them?
(In reply to comment #4) > Do the JavaScript bits duplicate PHP descriptions though, or load on top of > them? There are no javascript bits yet, hence this request. Once implemented they should use the same messages. Come to think of it, this logic is not in the Language class (despite the fact that we use it as Language:: commaList, it actually just uses Message. So in ResourceLoader: * Add message key "comma-separator" to your module definition * Use array.join( mw.msg( 'comma-separator' ) ); So although it can be simplified, its really trivial to just do yourself. And in case you're wondering if this is inconsistent with the server side, it isn't, because the server side implementation of Language::commaLIst is essentially the same: https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/core.git;a=blob;f=languages/Language.php;h=3ee959eb7a8314d7192acf32e17139994aa5d03f;hb=905d83e3ad0bc3e85438349537ff80dd999e7fc3#l3016