Search code examples
angularngx-translate

ngx-translate import translations after user has autheticated


I use ngx-translate for my application. We recently were told to not store these translation files in the /assets/* folder due to it having no security around it, and being publicly accessible.

I was curious if anyone knows of a way to load the translationModule or translations themselves until after the app has loaded, and a user has authenticated?

Or within the app.module.ts

export function HttpLoaderFactory(http: HttpClient) {
// return from the app folder not using http, and not from the /assets/i18n, instead of:
return new TranslateHttpLoader(http, '/assets/i18n/', '.json?cb=' + new Date().getTime());
}

Solution

  • This is what TranslateHttpLoader does for you. Just add the full URL instead of assets/i18n/, like the following:

    export function HttpLoaderFactory(http: HttpClient) {
      return new TranslateHttpLoader(http, 'http://YOUR_SERVER_URL/xyz', '');
    }
    

    You can add this factory to any module, not only the root module.