You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My app's main language is English, but it needs to support a few others, e.g.: Arabic. Arabic does not have the same pluralization rules as English, so I had to add a custom code to use "zero", "one", "two", etc. Unfortunately there are some missing translations in the app, where I need to fall back to English. However, when the pluralization key is not present, it crashes instead of giving the usual error message.
How to reproduce
import{I18n}from"i18n-js";consti18n=newI18n({"ar": {"weeks": {"one": "1 week ago","other": "%{count} weeks ago"}}});i18n.pluralization.register('ar',(_i18n,count)=>{// Based on https://github.com/ruby-i18n/i18n/blob/master/test/test_data/locales/plurals.rbif(count===0){return['zero'];}if(count===1){return['one'];}if(count===2){return['two'];}if([3,4,5,6,7,8,9,10].includes(count%100)){return['few'];}if(Number.isInteger(count)){return['many'];}return['other'];});i18n.locale='ar';console.log(i18n.t("not_existing",{count: 1}));// -> [missing "ar.not_existing" translation]console.log(i18n.t("weeks",{count: 1}));// -> 1 week agoconsole.log(i18n.t("weeks",{count: 2}));// -> Uncaught TypeError: message is undefined
What do you expect
It would be nice to get the same fallback as I have for missing keys (e.g.: [missing "ar.weeks.two" translation] )
Description
My app's main language is English, but it needs to support a few others, e.g.: Arabic. Arabic does not have the same pluralization rules as English, so I had to add a custom code to use "zero", "one", "two", etc. Unfortunately there are some missing translations in the app, where I need to fall back to English. However, when the pluralization key is not present, it crashes instead of giving the usual error message.
How to reproduce
What do you expect
It would be nice to get the same fallback as I have for missing keys (e.g.:
[missing "ar.weeks.two" translation]
)What happened instead
It raises an error and the whole page crashes.
Software:
i18n-js@4.2.0
Full backtrace
The text was updated successfully, but these errors were encountered: