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

Broken translation when using setTranslation in dynamic component #834

Closed
xeii opened this issue Apr 24, 2018 · 4 comments
Closed

Broken translation when using setTranslation in dynamic component #834

xeii opened this issue Apr 24, 2018 · 4 comments

Comments

@xeii
Copy link

xeii commented Apr 24, 2018

I'm submitting a ... (check one with "x")

[x ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[x ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Current behavior
When defining translations in dynamically loaded component some of the translations do not work. In the provided stackblitz either en, fr or both translations are missing depending on how the .defaultLang and .use are called.

Expected/desired behavior
I want a dynamically loadable component that would define its own translations. Also, the language change event from main application should reach the dynamic component.

Reproduction of the problem
https://stackblitz.com/edit/github-1ujje5

  • ngx-translate version: 10.0.0

  • Angular version: 6.0.0-rc.0 / 5.2.x in my application

  • Browser: [all]

@xeii
Copy link
Author

xeii commented Apr 25, 2018

@alexzuza
Copy link

alexzuza commented Apr 25, 2018

It has nothing to do with dynamic component.

Seems you have to wait till json file is loaded. Otherwise your dynamic translations will be overrided.

this.translate.getTranslation('en').pipe(take(1)).subscribe(() => {
  this.translate.setTranslation('en', {
    'DYNAMIC': 'I am dynamic component'
  }, true);
});

https://stackblitz.com/edit/github-1ujje5-8bya2x?file=src/app/app.component.ts

@xeii
Copy link
Author

xeii commented Apr 25, 2018

@alexzuza Thank you! I never thought they would be overridden that way around.

@xeii
Copy link
Author

xeii commented Apr 27, 2018

I found another issue, this time I swapped fr to be the default and used language. Now the translation in dynamic component is not working. Strangely enough, if swap around (as in change the order) the code blocks where translations are set in dynamic component, they start working again. Seems like another race condition.

I updated the stackblitz: https://stackblitz.com/edit/github-1ujje5-sugj8h

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

3 participants