-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
How to know when the translation bundles are loaded #455
Comments
I agree with @jiayihu, determining if the translations are loaded or not could be very useful. In my case, I'm developing a |
I needed the same functionality. |
no updates on this yet? pretty sad! |
I think this is a must fix to use ngx-translate. Client code need to know if things are loaded or not. |
I check it in this way.
|
Just use one of the following observables:
You would probably want to pipe it with a import { take } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core';
export class SomeComponentOrService
{
constructor(private translate: TranslateService)
{
this.translate.onDefaultLangChange.pipe(take(1)).subscribe(_ => doWhatYouWant());
}
} |
I am having trouble detecting when my translations have been loaded. I noticed that
is logging as
which means the translation was already available, but still the Why is this? |
Seems like you're translation id is reversed. It should match your data hierarchy. |
Yeah, that was a stupid mistake in my console.log. I did use the correct hierarchy in the actual code. Shame there is no generic |
So I did this:
and then in my controller I can do
|
A simple solution would be to expose a promise in your service and extract its class YourLangService
{
public isReady: Promise<string>;
private resolveIsReady: (locale: string) => void;
constructor(...)
{
this.isReady = new Promise<string>(resolve => this.resolveIsReady = resolve);
}
} Then subscribe to Now you could simply inject your service and query the promise: class SomeComponent
{
constructor(private lang: YourLangService)
{
this.lang.isReady.then(...);
}
} You could replace the promise with a |
I'm submitting a ... (check one with "x")
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 withshouldMerge
. (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 subscribingtranslate.use()
and setting a customAsyncSubject
, but I'm not sure it's the correctObservable
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
The text was updated successfully, but these errors were encountered: