lephyrus / ngx-translate-messageformat-compiler

Advanced pluralization (and more) for ngx-translate, using standard ICU syntax which is compiled with the help of messageformat.js.
MIT License
93 stars 29 forks source link

SelectOrdinal Error when Changing Languages #21

Closed Svoig closed 6 years ago

Svoig commented 6 years ago

I have a translation in my app that uses the selectOrdinal method in English, and the select method in Spanish. Both translations work correctly, but when I change from English to Spanish, I get the following error:

Uncaught Error: Invalid key `one` for argument `value`. Valid selectordinal keys for this locale are `other`, and explicit keys like `=0`.

It seems like the TranslateMessageFormatCompiler is parsing the old English translations for the Spanish locale.

This only happens the first time I change languages (or when I clear the cache), which makes me think that the TranslateHttpLoader hasn't finished loading the new translations before the compiler starts parsing.

Any thoughts?

lephyrus commented 6 years ago

I think you're right that this is a timing issue, which points to the TranslateService or in fact the translate pipe or directive, all of which is part of ngx-translate/core. The compiler works purely synchronously. I'm not saying I don't care, but figuring out this kind of issue can be complicated. I believe there is at least one if not several bugs related to async translation loading in ngx-translate, unfortunately. If you have the time, I encourage you to do some debugging and raise an issue on https://github.com/ngx-translate/core.

Questions you can try to answer to narrow down the problem:

Svoig commented 6 years ago

You're right - switching to a synchronous loader fixes the problem. Feel free to close this issue. Thanks for your help!