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.

Lazy loaded module specific JSON translation file not loading

See original GitHub issue

I’m submitting a

[x] feature request => load child module specific translation JSON file

Current behavior In my lazy loaded child module account.module.ts I’m importing TranslateModule with forChild()

@NgModule({
  imports: [
    CommonModule,
    HttpModule,
    FormsModule,
    AccountRoutingModule,
    TranslateModule.forChild({
      loader: { provide: TranslateLoader, useClass: AccountTranslationLoader, deps: [Http] },
    })
  ],
})
export class AccountModule { }

I have custom translate loader AccountTranslationLoader written as

export class AccountTranslationLoader implements TranslateLoader {

    constructor(private http: Http) {}

    getTranslation(lang: string): Observable<any> {
        return this.http.get(`./assets/i18n/account/${lang}.json`)
    }
}

Currently the expected json file request is never made and translation in child module views not working.

Expected/desired behavior It is expected to load the child module json translation file and append it to the previously loaded translation file loaded from AppModule using TranslateModule.forRoot()

Please tell us about your environment:

  • ngx-translate version: ^7.0.0

  • Angular version: ^4.1.3

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:14
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
matkarlgcommented, Jul 24, 2017

The GET request is never made because there are no subscribers on the Observable for fetching the child JSON. I assume translate.use() is used in the root to set language, which auto-subscribes and completes for root only Source: translate.use. It does not automatically fetch the JSON for the child.

Make a test by subscribing to onLangChange() manually in the child module and change the language in code. It should fetch the JSON.

2reactions
ratidzidziguricommented, Jul 12, 2018

@panagulis72 it does not work for me actually even in a child module which is lazy loaded it does not work and never loads language.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ngx-translate is not working for lazy loaded module
I want to implement ngx-translate in angular 5 project lazy loaded module wise its working for only parent module but not works in...
Read more >
Lazy translations loading from Angular | ISPsystem
The translations within the projects are stored in json files. ... We will indicate in the angular module what chunk of translation we...
Read more >
How to split your i18n file per lazy loaded module with ngx ...
To be able to load a json file along with a lazy loaded module you have to use the property isolate as the...
Read more >
Scope Configuration | Transloco Angular i18n - GitHub Pages
... a lazy load module, or a component's providers. Let's say we have a todos page and we want to create separate translation...
Read more >
Lazy-loading feature modules - Angular
Click on the Orders or Customers button. If you see a chunk appear, everything is wired up properly and the feature module is...
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