question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hide translation labels until language file is loaded

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report
[ ] support request
[ ] feature request

Question How do I hide translation labels until language file is loaded? I assume this would involve some kind of cloak directive.

Current behavior Problem is when I have something like {{ Section.Title | translate }}, Section.Title is visible until language file is loaded.

  • ngx-translate version: latest
  • Angular version: 4.0

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:30
  • Comments:16

github_iconTop GitHub Comments

13reactions
MJomaacommented, Sep 17, 2018

@lazabazsa

That’s what I do. (LocalSettingsService= custom service, Store = ngrx store)

providers: [
    {
      provide: APP_INITIALIZER,
      useFactory: appInitializerFactory,
      deps: [TranslateService, LocalSettingsService, Store, Injector],
      multi: true
    }
 ]

and

export function appInitializerFactory(translateService: TranslateService, localSettingsService: LocalSettingsService, store: Store<AppState>, injector: Injector): () => Promise<any> {
  return () => new Promise<any>((resolve: any) => {
    const locationInitialized = injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
    locationInitialized.then(() => {
      translateService.addLangs(['en', 'de']);
      translateService.setDefaultLang('en');
      let selectedLanguage = localSettingsService.getSelectedLanguage();
      if (!selectedLanguage) {
        const browserLang = translateService.getBrowserLang();
        selectedLanguage = browserLang.match(/en|de/) ? browserLang : 'en';
      }
      translateService.use(selectedLanguage).pipe(take(1)).subscribe(() => store.dispatch(new HydrateSelectedLanguageAction(selectedLanguage)),
        err => console.error(err), () => resolve(null));
    });
  });
}
7reactions
luzanovdmcommented, Jul 2, 2018

Has anyone found a solution to this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular-translate is not translating with loaded static file
If it is not found, in your template, it will just print out label.test instead of the actual translation It works from JSON....
Read more >
Considerations for Working with Translation Files
Deleting a translation value, row, or trans-unit tag in the file doesn't remove the translation after the file is imported. To delete a...
Read more >
Configuration Options - i18next documentation
language to use if translations in user language are not available. Setting it explicitly to false will not trigger to load the fallbackLng...
Read more >
How to translate your Angular app with ngx-translate
1. Add ngx-translate to your Angular application 2. Set up the TranslateService in your app.module.ts 3. Create your main language translation file (in...
Read more >
Working with SalesForce Translation Files (stf Files)
Working with the Bilingual File · An asterisk (*): The label is out of date. A change was made to the default language...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found