setTranslate does not work
Hi,
I use setTranslation to add another translation, but the translate pipe does not resolve the entry.
At my program start I execute the following statement:
translate.setTranslation(lang, {HELLO: "foo"}, true);
And in my template I resolve the translation:
{{ 'HELLO' | translate }}
I can confirm that all other translations which got added by .json files through the normal startup and loading routines of ngx-translate work fine, but only my manual translation (in this case HELLO) fails. Does anyone know what I am doing wrong?
Thanks a lot!
I find up (in my situation) it is json import problem.
Same case for me. It is intermittent. Sometimes it works, sometimes it doesn't
And I'm pretty sure the second parameter always gets filled.
I tried using a Custom Loader instead of manually setting and again, no luck after publishing the package and importing it at a different project
angular 8, ngx-translate core 11
Any update on this problem? We're facing the same behaviour.
"@ngx-translate/core": "^11.0.1",
"@ngx-translate/http-loader": "^4.0.0",
app.module
export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
return new TranslateHttpLoader(http, assetUrl('i18n/'));
}
const translateModuleConfig = {
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient],
},
};
imports: [
...
TranslateModule.forRoot(translateModuleConfig),
...
app.component
public ngOnInit() {
this.translateService.setTranslation(language, { HELLO: "TEST" }, true);
this.translateService.use(language);
this.language = language;
this.translateService.getTranslation(language).subscribe(lang => console.log({ lang }));
}
console.log outputs only translations from json file.
Same issue but only once built, works fine in NG 12 and in serve mode.
Turns out it was down to the translation service working in a non-singleton context and therefore loosing the translations at some point down the line 🤷♂️
Turns out it was down to the translation service working in a non-singleton context and therefore loosing the translations at some point down the line 🤷♂️
Hi @smasala, how did you solve this problem?
Turns out it was down to the translation service working in a non-singleton context and therefore loosing the translations at some point down the line 🤷♂️
Hi @smasala, how did you solve this problem?
Can't remember exactly, don't have the code base anymore. I think it had to do with the dependency injection scope (provideIn).