-
-
Notifications
You must be signed in to change notification settings - Fork 627
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
Question: Is it possible to lazy-load a language namespace on first use? #570
Comments
the problem here is it is only possible when you can load the files in a synchronous way as calling t returns the translation. v1 of i18next had that option but as browsers started to warn about doing synchronous xhr calls that option got dropped. to optimize your case - if you're using the xhr-backend:
so at least you don't have to load every namespace for the one key you need in fixed language t('some.key', {lng:'fr'}) May i ask your usecase? why you need to display one part in fr while user language is en? |
That makes perfect sense. I was just vaguely thinking about possibilities for a translation interface I'm building but hadn't really considered it would require sync XHR which I knew had been removed in v2. I think preload will be fine for our use case, the part that needs multiple languages isn't customer facing so I don't care too much about initial load time. Thanks for taking the time to explain, useful to know about |
hi @mjmasn can you provide more details on what you plan to build? jan.muehlemann@gmail.com i'm very interested on that because we plan ourself to create some translation interface for a 'translation as a service' platform for i18next using companies. |
@jamuhl sure, should have some time over the weekend :) |
Given:
If I init i18next with
lng:'en'
, I would expect that callingt('some.key', {lng:'fr'})
would automatically attempt to load the relevant 'fr' translations (assuming i18next knows the possible languages - e.g. by settingwhitelist: ['en','fr']
). However it just returns the english translation. Is there any way to do this automatically? I can just use preload or call loadLanguages when required but would rather not load all namespaces for all languages on the client.The text was updated successfully, but these errors were encountered: