fallbackLang sometimes doesn't work
Closed this issue · 0 comments
Right now we are using the Accept-Language header to initialize the app with the proper language, but if the user sends a header with a value for which we don't have translations (let's say es-ES), if I set the fallbackLang
prop in the I18n
component to be en-US, I would expect that the translations for this default language are used, but what ends up happening is that the translation keys are returned by the trans
function inside the I18n
component.
I would expect this function to use the translation for the default language instead if there is one set.
This error actually happens with a store state that looks like this:
// No es-ES key
i18nState: {
translations: {
'en-US': {...} // English translations
}
}
But if I define an initial state like the next one, the bug does not occur and the fallback language prop works as expected:
i18nState: {
translations: {
'en-US': {...}, // English translations
'es-ES': {} // Empty object
}
}
This becomes an issue when the translation keys are just keys and not a message as it happens in some of the examples in the readme file.
I think it would make sense that thetrans
function used the fallback language translations even if langMessages
is undefined.
I think the fix would be quite easy, but before working on an implementation I wanna sure that this is a fix that is wanted.. so I already created a PR with a fix. If this fix is not desired, please close this issue and the linked PR.
I think this explains well what the problem is, but if you need more details, please let me know.
Thank you very much.