Skip to content
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

setTranslation is confusing the translation #1454

Open
Chris-Max-P opened this issue Oct 30, 2023 · 0 comments
Open

setTranslation is confusing the translation #1454

Chris-Max-P opened this issue Oct 30, 2023 · 0 comments

Comments

@Chris-Max-P
Copy link

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


ngx-translate version: 14.0.0
Angular version: 15.2.5


Browser:
- electron.js: 23.1.4
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant