Last modified: 2012-07-11 20:06:48 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T40307, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 38307 - JavaScript's mw.language should provide a parallel to Language->commaList( $arr );
JavaScript's mw.language should provide a parallel to Language->commaList( $a...
Status: NEW
Product: MediaWiki
Classification: Unclassified
Internationalization (Other open bugs)
unspecified
All All
: Lowest enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-11 15:17 UTC by Jarry1250
Modified: 2012-07-11 20:06 UTC (History)
5 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Jarry1250 2012-07-11 15:17:51 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).
Comment 1 Alex Monk 2012-07-11 15:49:02 UTC
For most languages arr.join(', ') will work.
Comment 2 Jarry1250 2012-07-11 16:17:25 UTC
(In reply to comment #1)
> For most languages arr.join(', ') will work.

Yes, but which? :)
Comment 3 Alex Monk 2012-07-11 16:19:41 UTC
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.
Comment 4 Jarry1250 2012-07-11 17:58:52 UTC
Do the JavaScript bits duplicate PHP descriptions though, or load on top of them?
Comment 5 Krinkle 2012-07-11 20:06:32 UTC
(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

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links