rbalet / ngx-translate-multi-http-loader

A loader for ngx-translate that loads translations with http calls
MIT License
77 stars 15 forks source link

Loading multiple translation files from same directory #2

Closed Sandeep321 closed 6 years ago

Sandeep321 commented 6 years ago

What I am looking for is that I would want to divide the translation files into smaller ones, keeping all the translation files in the same directory. So, instead of using something like core and shared folders, Can we load all the translation files for the same language from the current folder.

It might be possible that I have files names like:

Sandeep321 commented 6 years ago

Can I write something lime :
return new MultiTranslateHttpLoader(httpClient, [ {prefix: "./assets/translate/core/*.", suffix: ".json"}
]); which would match all en files for en language. e.g - messages-headers.en.json messages-headers.en-UK.json messages-details.en.json messages-details.en-US.json

denniske commented 6 years ago

You can use this:

export function HttpLoaderFactory(httpClient: HttpClient) {
  return new MultiTranslateHttpLoader(httpClient, [
      {prefix: "./assets/translate/core/messages-headers.", suffix: ".json"},
      {prefix: "./assets/translate/core/messages-details.", suffix: ".json"},
  ]);
}

Note that you have to write the name of each file there. You cannot just use {prefix: "./assets/translate/core/*.", suffix: ".json"} because the client on which this code runs does not know which translation files are on the server. You would need to concatenate all translation files for each language in the build process. Something like this https://github.com/ngx-translate/http-loader#angular-cliwebpack-translateloader-example with deep-merge.

Sandeep321 commented 6 years ago

That's what I am doing now. Thanks for the reconfirming. Closing the issue then.