Lang.js is a simple and lightweight library to handle in the browser: github.com/rmariuzzo/Lang.js

The API is close to Laravel, allowing to use Laravel language files in both Blade and JavaScript.

While doing researches, I also learned various interest things about pluralization in languages.

1/x

Follow

Languages can have from 1 to 6 plural forms. There’s a Unicode standard (cldr.unicode.org/index/cldr-sp) on the naming of these rules in order to pick the right plural form:
- zero
- one
- two
- few
- many
- other

Russian and Arabic: use all of them.
English and French: 2 of them.

Aside from Lang.js, you can also use the `Intl.PluralRules` API (not on IE): developer.mozilla.org/en-US/do).

It helps detecting which pluralization rule you should apply for a given language and quantity.

2/x

3/3

See also Lingui (lingui.js.org/guides/plurals.h), another lib.

If you want to compile Laravel lang files to JSON that will be loaded by your front-end, you can also use `laravel-js-localization`(github.com/rmariuzzo/Laravel-J).

I don’t use it. I’ll elaborate on how I use Lang.js with Laravel once my solution will be battle-tested in a wider range of situations.

Sign in to participate in the conversation
NintendojoFR

Ceci est l'instance du site NintendojoFR. Elle est réservée aux membres de la rédaction et à nos chers lecteurs qui souhaitent avoir un compte.