-
-
Notifications
You must be signed in to change notification settings - Fork 642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow default value in nested translation #2174
Comments
There are 2 options: Option 1: Use multiple fallback keys like described here: https://www.i18next.com/translation-function/essentials#multiple-fallback-keys import i18next from 'i18next';
i18next.init({
fallbackLng: 'en',
resources: {
en: {
translation: {
message: "Something went wrong:",
error: {
"unspecific": "$t(message) Unknown error",
"it_error": "$t(message) it went wrong"
}
}
}
}
})
const existingError = 'it_error'
const nonExistingError = 'other_error'
console.log(i18next.t([`error.${existingError}`, 'error.unspecific']))
console.log(i18next.t([`error.${nonExistingError}`, 'error.unspecific'])) Option 2: Update i18next to v23.11.2 ;-) |
Wow that was quick. Tnx! |
If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project. There are many ways to help this project 🙏 |
🚀 Feature Proposal
Currently I don't think its possible to provide a default value for when a nested translations cannot be found.
Motivation
When templating nested translations, its posible that the nested key is not present, so it would lead to a broken translation.
Example
Given the following translation file:
t('message', {error_type: 'other_error'})
will translate to"Something went wrong: error_code.other_error"
but I would like it to translate to"Something went wrong: Unknown error"
.The text was updated successfully, but these errors were encountered: