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
How to use Translation outside a React component? #1236
Comments
I didnt understand, can you please give more detail |
befire using the t function, i18next needs to have finished to initialize and be ready. |
Something like: import i18n from '../../../i18n';
const data = {};
function updateTranslations () {
data.code = i18n.t('key1');
data.message = i18n.t('key2');
}
// i18next seems ready -> initial fill translations
if (i18n.isInitialized) {
updateTranslations();
}
// reset translations to new values on language change
i18next.on('languageChanged', function(lng) {
updateTranslations();
});
// we loaded some translation file? reset needed?!?
// https://www.i18next.com/overview/api#store-events
i18next.on('loaded', function(lng) {
updateTranslations();
});
export default data; |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Just like that:
|
but if we have:
is not going to work, requires to be function, any solution for this so i can avoid converting it into fn:
|
@AndonMitev spamming 3 issues...but not able to search for relavant...idk...#1698 (comment) |
Thanks for replying, i have attached event listeners and it works! But there is another issue with loading files using ths config:
Throws:
Also |
@AndonMitev https://www.i18next.com/principles/fallback#language-fallback is done depending on detected language... failed parsed has nothing todo with i18next...must be a wrong file or invalid json |
Hi, I'm trying to add translation to a object that is outside a React Component, is this possible?
Current code
The text was updated successfully, but these errors were encountered: