translate.use(langCode) is not working in some cases
See original GitHub issueCurrent behavior
In app.component.ts
I have set up the TranslateService
as follows:
translate.addLangs(['en', 'bn']);
translate.use('en');
translate.onLangChange.subscribe((change) => {
console.log('langChange', change);
})
In another module, I’m doing this to change the current language,
this.translate.use(langCode);
When I change the language to bn
, it does not work.
BUT, if I write translate.use('bn');
in app.component.ts
, language change starts working.
What I’ve noticed is that, when I set en
as the language in app.component.ts
the onLangChange
prints an empty object as the translations
property.
// in onLangChange callback
Object { lang: "bn", translations: {} }
Expected behavior
Changing language should work regardless of what language was set during initialization
How do you think that we should fix this?
Minimal reproduction of the problem with instructions
Environment
ngx-translate version: 13.0.0
Angular version: 10.1.5
Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ x] Firefox version 81
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: 12.16
- Platform: Windows
Others:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:8
Top Results From Across the Web
ngx-translate is not working for lazy loaded module
The Problem. Calling TranslateService.use('[LANG-CODE]') does change the translation in my menu-bar component.
Read more >Cannot save translated nodes after upgrading to 8.8 ... - Drupal
Problem /Motivation Hm. Perhaps I'm doing sth. wrong, but after upgrading a few sites to Drupal 8.8 I found that I cannot save...
Read more >How to translate your Angular app with ngx-translate
1. Add ngx-translate to your Angular application 2. Set up the TranslateService in your app.module.ts 3. Create your main language translation file (in...
Read more >Translation | Django documentation
Installing a global _() function causes interference. Explicitly importing gettext() as _() avoids this problem. What functions may be aliased as ...
Read more >ng2-translate - Bountysource
Another moment when i use like this it will not translate ... It had worked for me on AngularJS with my library ocLazyLoad...
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
This workaround works for me (angular 11 et ionic 5) :
I force to load all possible language in app.components :
this.translate.addLangs([‘fr’, ‘en’, ‘es’, ‘de’])
this.translate.use(‘en’) this.translate.use(‘es’) this.translate.use(‘de’) this.translate.use(‘fr’)
then in other component, i can call again this.translate.use(‘xxx’)
This issue was not present in previous version for angular 8
Hi guys! I also noticed this “issue”. After a few attempts, I got it by using same loader config in
forChild
as inforRoot
:app.module.ts
(can becore.module
or whatever):app.component.ts
:lang-test-module.ts
(the module from where we want to change lang):I don’t know if it is a good solution…