How to know when the translation bundles are loaded
See original GitHub issueI’m submitting a … (check one with “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
I have the necessity to know then the translation bundle is loaded and only then do some extra work.
In my case I need to load other modules translations (not lazy-loaded) and I noticed that when a bundle is loaded it completely overrides existing translations instead of merging like setTranslation
does with shouldMerge
. (Probably related to this line of code, I’ll make a PR if necessary.)
Therefore I need a way to know when the AppModule
bundle is loaded with the specified loader. For the time being I resolved subscribing translate.use()
and setting a custom AsyncSubject
, but I’m not sure it’s the correct Observable
to subscribe to.
Another way would be maybe creating a custom loader with an AsyncSubject
, but wouldn’t be very different from the former solution I suppose.
-
ngx-translate version: 6.0.0
-
Angular version: 2.4.x
Issue Analytics
- State:
- Created 7 years ago
- Reactions:15
- Comments:11
Top GitHub Comments
Just use one of the following observables:
onDefaultLangChange
onLangChange
onTranslationChange
You would probably want to pipe it with a
take(1)
operator to avoid triggering your code multiple times (and also release memory by having the observable complete after one emission):I needed the same functionality. Why not just check
translateService.store.translations
if it’s empty or not.