core icon indicating copy to clipboard operation
core copied to clipboard

How to localize content coming from third party libraries in Angular

Open tarushreeS opened this issue 4 years ago • 1 comments

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.

tarushreeS avatar Sep 20 '21 10:09 tarushreeS

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

rbalet avatar Nov 18 '21 16:11 rbalet