core icon indicating copy to clipboard operation
core copied to clipboard

Translations not loaded on first start

Open fortunella opened this issue 5 years ago • 8 comments

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 avatar Feb 26 '20 16:02 fortunella

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.

fortunella avatar Feb 27 '20 09:02 fortunella

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

blumk avatar Aug 30 '20 11:08 blumk

Is there an update or workaround for this issue?

do-nat avatar Jan 11 '22 09:01 do-nat

any update on this one?

brandart avatar Apr 19 '22 11:04 brandart

Any updates here ?

ajlif avatar May 12 '22 08:05 ajlif

any update?

yogawa avatar Jun 20 '23 20:06 yogawa

Any updates? Is this ever getting fixed?

Evand3r avatar Aug 31 '23 16:08 Evand3r

still not fixed

MoathTar avatar Feb 11 '24 16:02 MoathTar