ngx-translate/http-loader

Loading Translations . json from an external npm package

tnicola opened this issue · 1 comments

Hi there,

All my translations files are in a external library e.g. @translations/my-translations. I cannot access to node_modules at runtime. How could I load them using @ngx-translate/http-loader?

Thanks.

This helped me out: https://stackoverflow.com/questions/41555624/how-to-include-assets-from-node-modules-in-angular-cli-project .

Just follow the instructions and add your external assets in Angular CLI (.angular-cli.json) like is described in the solution.

"assets": [
  "assets",
  { "glob": "**/*", "input": "../@translations/my-translations/", "output": "./translations/" }
]

These assets will be included in the dist (outDir) folder. Then simply load them with:

export function HttpLoaderFactory(http: HttpClient) {
    return new TranslateHttpLoader(http, "/translations/", ".json");
}

Closing the issue.