You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my app I get some translations from the server. When received I want to update the translations. For this I use setTranslation.
I have the following code in my app: for (let lang of ["de", "en"]) { let serverTranslations = translations.filter(t => t.language === lang); this.translateService.getTranslation(lang).subscribe((localTranslations) => { for (let translation of serverTranslations) { // @ts-ignore localTranslations[translation.key] = translation.text; } this.translateService.setTranslation(lang, localTranslations); }); }
where serverTranslations is an array of type {key: string, text: string, language: string}.
A confirm dialog is shown after the import. The problem is, that the confirm dialog has wrong translations: When the language is "de" and the import is done, the texts in the confirm dialog are translated in language "en". I found that when I change the order in the for loop to ["en", "de"], the texts are translated to german instead.
So I assume that setTranslation does impact the translations that are used right after the method is called. All the following translations are correct again, even on the same page of my web app.
Not sure if it has something to do with it, but the confirm-dialog is opened by using an EventEmitter subscription. I observed differences when the confirm-dialog was opened directly.
Expected behavior
I expect the translations to be in the language that is currently set, not the one that setTranslation used last.
How do you think that we should fix this?
I don't know where the problem originates from, so I cannot answer this one.
Minimal reproduction of the problem with instructions
Current behavior
In my app I get some translations from the server. When received I want to update the translations. For this I use setTranslation.
I have the following code in my app:
for (let lang of ["de", "en"]) { let serverTranslations = translations.filter(t => t.language === lang); this.translateService.getTranslation(lang).subscribe((localTranslations) => { for (let translation of serverTranslations) { // @ts-ignore localTranslations[translation.key] = translation.text; } this.translateService.setTranslation(lang, localTranslations); }); }
where serverTranslations is an array of type {key: string, text: string, language: string}.
A confirm dialog is shown after the import. The problem is, that the confirm dialog has wrong translations: When the language is "de" and the import is done, the texts in the confirm dialog are translated in language "en". I found that when I change the order in the for loop to ["en", "de"], the texts are translated to german instead.
So I assume that setTranslation does impact the translations that are used right after the method is called. All the following translations are correct again, even on the same page of my web app.
Not sure if it has something to do with it, but the confirm-dialog is opened by using an EventEmitter subscription. I observed differences when the confirm-dialog was opened directly.
Expected behavior
I expect the translations to be in the language that is currently set, not the one that setTranslation used last.
How do you think that we should fix this?
I don't know where the problem originates from, so I cannot answer this one.
Minimal reproduction of the problem with instructions
I could reproduce the error here: https://stackblitz.com/edit/github-rdb8xe?file=src%2Fapp%2Fapp.component.ts
Note that the translation does not have the same behaviour in the opened dialogs. Sometimes it is the french translation, sometimes the english, but I think it's the same bug as for me.
Environment
The text was updated successfully, but these errors were encountered: