Losing translation with ngx-translate when giving build with ng prod

    // translate
    import { Globalization } from '@ionic-native/globalization';
    import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; 
    import { TranslateHttpLoader } from '@ngx-translate/http-loader'; 

    export function createTranslateLoader(http: HttpClient) { 
      return new TranslateHttpLoader(http, './assets/i18n/', '.json'); 
    } 

    TranslateModule.forRoot({ 
      loader: { 
        provide: TranslateLoader, 
        useFactory: createTranslateLoader, 
        deps: [HttpClient] 
      } 
    }), 

I'm working on a project made in Ionic 3.

When I give a ionic cordova run android --livereload the translation works normally.

But when I use ionic cordova run android --prod or ionic cordova build android --prod the translation does not work anymore, someone has already gone through it and could you help me?

Author: Rafael Zulianeli, 2019-09-26

1 answers

Below is an image of how the folder structure for the translation was made.

Structure made for translation

As described in the question imports, I use Globalization to pick up the preferred language of the device and in another file I use TranslateService

import { TranslateService } from "@ngx-translate/core";

const lang = TranslateService.getBrowserCultureLang()

The function getBrowserCultureLang gives me the browser preference...

Both give me the extension with the culture:

Lang = 'pt-BR'

Or

Lang = 'en-US'

What was happening was that I passed the lang in the function TranslateService.setDefaultLang(lang); the way it was handed to me.

Is required pass the lang with all contents in lowercase.

Ex: TranslateService.setDefaultLang(lang.toLowerCase())

Lang = 'pt-br'

Or

Lang = 'en-us'

 0
Author: Rafael Zulianeli, 2019-09-30 16:42:19