News for hackers. Stuff that matters.
Re:FormatJS – Internationalize your web apps on the client a... by drewfish on Tuesday October 14, 2014 @01:09PM (#8454443)
Yeah, for a simple plural that can be a bit longer. In other languages, though, the pluralization rules get rather complicated[1]. (For example, Arabic has both complicated pluralization rules -and- a lot of people who speak it.)

The strength of the ICU message format, in my mind, is that the messages can be "nested" so that the translation can be customized for multiple concerns (plural, gender, whatever).

Also, with the integrations (dust, handlebars, react) the details of translation and display of data lives in the message format and/or template. This is the "view layer", and means that your controller/code isn't littered with a bunch of calls to a translation library.

[1] http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/la...

Re:FormatJS – Internationalize your web apps on the client a... by mikewhy on Tuesday October 14, 2014 @07:23PM (#8456388)
Nice, I didn't know that about Arabic, and the many other languages.

Though i18n-js does let you write your own pluralizations rules (taken from the readme), while supporting zero/one/many out of the box:

    I18n.pluralization["ru"] = function (count) {
      var key = count % 10 == 1 && count % 100 != 11 ? "one" : [2, 3, 4].indexOf(count % 10) >= 0 && [12, 13, 14].indexOf(count % 100) < 0 ? "few" : count % 10 == 0 || [5, 6, 7, 8, 9].indexOf(count % 10) >= 0 || [11, 12, 13, 14].indexOf(count % 100) >= 0 ? "many" : "other";
      return [key];
    };
I've posted an example below, but I don't consider `@div null, @t('welcomeMessage', { username })` "littering" my code.
Re:FormatJS – Internationalize your web apps on the client a... by drewfish on Wednesday October 15, 2014 @02:17AM (#8457358)
There are a few NPM libraries (make-plural, cldr, probably others) which will help you write those pluralization functions. The CLDR data does get updated from time to time, so it's nice to rely on another package to trace those changes.