@gauz09 wrote:
I am trying to implement Internationalization in my app. It works as required with
ionic serveon desktop but fails on Android device after I runionic cordova run android.I get the following on Android device when I inspect it:
Failed to load resource: net::ERR_FILE_NOT_FOUND /android_asset/assets/i18n/en.json
Would appreciate if somebody can please help resolve it.
I have done following:
Created en.json and other files in
project_folder/src/assets/i18nfolder.In
app.module.tsfile, added below lines:import { TranslateModule, TranslateStaticLoader, TranslateLoader } from 'ng2-translate/ng2-translate'; export function createTranslateLoader(http: Http) { return new TranslateStaticLoader(http, '../assets/i18n', '.json'); } @NgModule({ declarations: [ MyApp, . . ], imports: [ IonicModule.forRoot(MyApp), TranslateModule.forRoot({ provide: TranslateLoader, useFactory: (createTranslateLoader), deps: [Http] }), . . . ], bootstrap: [IonicApp], entryComponents: [ // all components ], providers: [ . . . ] })Then in my
app.component.tsfile, I have this:initializeApp() { this.platform.ready().then(() => { this.statusBar.styleDefault(); this.splashScreen.hide(); let userLang = navigator.language.split('-')[0]; userLang = userLang.match(/cn|en|es|ja|it|ru/) ? userLang : 'en'; this.translate.setDefaultLang('en'); this.translate.use(userLang); }); }And finally, in all my HTML files, I have the following to get the actual label value from correctly loaded language file.
{{'PAGE.label' | translate}}As I said all this works fine with
ionic servecommand on desktop but it just prints the "{{'PAGE.label' | translate}}" as is on the UI when I try it on an Android device withionic cordova run androidcommand.Any idea on what I might be missing?
Thanks.
Posts: 1
Participants: 1