ngx-translate / core

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

How to localize content coming from third party libraries in Angular #1336

Open tarushreeS opened 3 years ago

tarushreeS commented 3 years ago

I am using multiple libraries in my angular application. I want to understand how I can localize contents coming from these libraries or is there a way to load their translation files in the application? I want to load the library translation files as and when used.

rbalet commented 3 years ago

Hi @tarushreeS, You can indeed export assets file from your library into a new one.

Here's an example on how to do it. https://stackoverflow.com/a/64589400/11135174.

For you, you just have to move the i18n files into the assets folder and then reference it like that.

// app.module.ts
export function HttpLoaderFactory(http: HttpClient) {
  return new MultiTranslateHttpLoader(http, ['/assets/i18n/', '/assets/vendors/i18n/'])
}
// angular.json
 "assets": [
      "src/assets",
      {
        "glob": "**/*.json",
         "input": "node_modules/@your-library/project-name/assets",
         "output": "/assets/vendors/i18n/"
      },

@ocombe I think you shall close this issue