ngx-translate / core

The internationalization (i18n) library for Angular
MIT License
4.53k stars 578 forks source link

Translations not loaded on first start #1178

Open fortunella opened 4 years ago

fortunella commented 4 years ago

Current behavior

I use ngx-translate in an Ionic 4 app. When I deploy the app to a device on the first start the translations are not loaded. If I exit the app and restart it, everthing works fine.

Expected behavior

Translations are loaded on first start of the app.

Minimal reproduction of the problem with instructions

  1. Build the Ionic app with initialization of ngx-translate as in the docs
  2. Deploy app to a device (Android or iOS)
  3. Start the app

Environment


ngx-translate version: 12.1.1
Angular version: 8.2.14

In my app.component.ts I initialize ngx-translate as described in the docs:

constructor(public translate: TranslateService) {
    this.translate.setDefaultLang('de');
    this.translate.use('de').subscribe(
      next => { console.log('Initialized translations') }
    );
}

It seems that the use() method does not work correctly on the first start. The output inside the subscribe does not appear on the first start, but one the second.

Maybe its related to #1162 or #1175

fortunella commented 4 years ago

I found a workaround that works for me, but it's a bit hacky.

I created a class Labels that holds the labels from the JSON files. In my app.component.ts I set the translations explicitly with the values from this class when I configure the translate service.

    this.translate.setTranslation('de', Labels.get('de'));
    this.translate.setTranslation('en', Labels.get('en'));

This works on the first start, but now I have to maintain two versions of the translations as I want to switch back to the official way with http-loader when the bug is fixed.

blumk commented 4 years ago

@fortunella I can reproduce this issue in a non-Ionic environment. Using @angular/core and @ngx-translate/core 13.0.0.

Occurs mostly on initial page load. Translations load after reloading window, I guess because *.js bundles are already in cache.

do-nat commented 2 years ago

Is there an update or workaround for this issue?

brandart commented 2 years ago

any update on this one?

ajlif commented 2 years ago

Any updates here ?

yogawa commented 1 year ago

any update?

scarela commented 1 year ago

Any updates? Is this ever getting fixed?

MoathTar commented 9 months ago

still not fixed