8000 setTranslate does not work · Issue #1254 · ngx-translate/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

setTranslate does not work #1254

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

Closed
MMcKester opened this issue Oct 5, 2020 · 8 comments
Closed

setTranslate does not work #1254

MMcKester opened this issue Oct 5, 2020 · 8 comments

Comments

@MMcKester
Copy link
MMcKester commented Oct 5, 2020

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!

@beautifulinda
Copy link
beautifulinda commented Mar 15, 2021

I find up (in my situation) it is json import problem.

@FlavioRodr
Copy link

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

@kmiasko
Copy link
kmiasko commented Jul 5, 2021

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.

@smasala
Copy link
smasala commented Jul 21, 2021

Same issue but only once built, works fine in NG 12 and in serve mode.

@smasala
Copy link
smasala commented Jul 21, 2021

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 🤷‍♂️

@Heila-Almogren
Copy link

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?

@smasala
Copy link
smasala commented May 7, 2023

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).

@rbalet
Copy link
Collaborator
rbalet commented Jun 2, 2025

Could you provide a stackblitz?

I'm closing the issue in the meantime, as this is an old one.

Happy coding <3

@rbalet rbalet closed this as completed Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants
0