Sometimes DefaultLang translations are not loaded when starting the app
See original GitHub issueCurrent behavior
This issue may be similar to: https://github.com/ngx-translate/core/issues/1162.
In my case I noticed that the app, while in production, sometimes fails to fallback to the default language on the first loaded screen (i.e. app first startup on load).
For example:
- Main resources file is ‘en.json’. There is also an additional ‘es.json’ which is empty ‘{}’.
- When the app loads it sets ‘en’ as the default language:
this.translate.setDefaultLang('en');
- The app upon startup sets the current lang to ‘es’:
this.translate.use('es')
. - In this case, sometimes, the fallback to ‘en’ fails and I see the resource key instead.
Some observations:
- If the app sets the language to be ‘en’ on startup, I don’t see the problem reoccur.
- If the es.json file is not empty but has a translation, the problem does not occur.
For these reasons I suspect that the problem is with falling back to the default language when a resource is missing.
I tried various solutions to delay loading and ensure the translations are available but unfortunately could not workaround these problems. Here are some of the things I tried:
- https://stackoverflow.com/a/38919198/3208034
- https://stackoverflow.com/a/65835085/3208034
- https://www.vitamindev.com/angular/how-to-load-translations-when-the-application-starts/
Expected behavior
The default language should be used for missing keys in the selected language, also upon application startup.
Environment
ngx-translate version: 13.0.0
Angular version: 12.1.0
Browser:
- Chrome (desktop) version 95
For Tooling issues:
- Node version: 14.17.1
- Platform: win32 x64
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
ngx-translate sometimes not load json on init - Stack Overflow
I have an angular application with 3 languages: Spanish, English and Catalan. The app is deployed in Production,and we are facing a very ......
Read more >ngneat-transloco/lobby - Gitter
Iam kinda new to angular and id like to have translations in my app. ... is it normal to sometimes have the files...
Read more >Internationalizing your Angular app - Briebug Blog
It includes schematics, supports Ivy, testing, supports multiple fallbacks, lazy loading translations, and even Universal. Implement Transloco.
Read more >Introducing Transloco: Angular Internationalization Done Right
It's responsible for instructing transloco how to load the translation files. ... Sometimes you may need to translate a key in a component...
Read more >Google Translate Community
Trending posts ; Anyone aware that after the Android 10 roll-out The Tap to translate no longer will display over app · 3...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @ewolfman. I had the same problem, which came funnily from my httpInterceptor.
I was using the angular
http
to load my file, but it was then delayed by my httpInterceptor, which then had created a problem while instantiating theTranslateService
.Here’s how I fixed it.
1. I recreated the MultiTranslateHttpLoader to be able to add the
X-Skip-Interceptor
2. Skip it in the httpInterceptor
Here, I listen to the headers, if it does have the InterceptorSkipHeader, skip it
@ocombe I think this could be communicated somewhere in the wiki
@ocombe Feel free to close this issue since I took over the library that was causing the problem & fixed the problem there