conedevelopment / i18n

Push your Laravel translations to the front-end and use them easily with JavaScript.
https://pineco.de/using-laravels-localization-js/
MIT License
129 stars 21 forks source link

JS implementation of trans_choice doesn't match PHP implementation #35

Open marijnvdwerf opened 2 years ago

marijnvdwerf commented 2 years ago

Found out that (simplified) trans_choice(":count messages", 2) throws an error, while Laravel itself is fine with it. Did a bit of digging, and found that there's various cases where I18n.js behaves differently from the framework.

Testcases: https://jsbin.com/ruzaceyawo/edit?js,output Laravel Framework testcase: https://github.com/laravel/framework/blob/9.x/tests/Translation/TranslationMessageSelectorTest.php

Another (seperate) issue is the "default pluralisation" rules are based on the en locale. Others can have more entries, and different rules.

E.g.

public function getPluralIndex($locale, $number)
    // ...
    case 'uk':   
        return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
    // ...
}
iamgergo commented 2 years ago

Hi, thanks for the report!

Yes I see. I'm not sure I could fix this quickly.

Are you planning to make a PR? We could start with one language and then we could extend it.

What do you think?

Thanks!