Albin Jordan
Albin Jordan

Reputation: 43

ngx-translate: Load JSON from Angular 6 library

I am building Angular 6 application with 3 libraries ...

I would like to have 3 json files containing translations in each of them.

Is it possible to have TranslateLoader that reads those files from installed libraries. So that I could say something like

new TranslateLibraryLoader(http, ["@company/lib1", "@company/lib2", 
"@company/lib3", "./assets/i18n/"]

Upvotes: 2

Views: 1228

Answers (1)

Giacomo Voß
Giacomo Voß

Reputation: 1067

ngx-translate needs the files from the libraries at runtime. So first you have to tell angular to integrate these files in your build. In your angular.json do:

"assets": [
  {
    "input": "./path-to-company/lib1/translations.json",
    "bundleName": "translations.lib1.json",
    "lazy": true
  },
  // repeat for all libs
],

Then you can configure a TranslateHttpLoader to load these files or implement your own one:

export function HttpLoaderFactory(http: HttpClient) {
    return new TranslateHttpLoader(http, yourPath, yourSuffix);
}

Upvotes: 2

Related Questions