Reputation: 63
First, I've read the previous threads regarding this. And none of the solutions worked for me.
I have a Cordova-based app (not ionic) which is deployed on android and iOS. Everything works fine except that my translations doesn't work on iOS devices (neither simulator or real device). I'm using ngx-translate and it there's no problem in the browser or on Android-devices.
Here's my setup:
app.module.ts
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
}),
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
app.component.ts
import localeSv from '@angular/common/locales/sv';
ngOnInit(): {
this.translate.setDefaultLang('se');
registerLocaleData(localeSv);
}
Implementation:
<div translate>Click to close</div>
I've also tried using other translate styles like this.translateService.instant('something'), but it's not working.
After running cordova build ios I can see that my se.json file is in the correct folder: /assets/i18n/se.json
Version info:
"@ngx-translate/core": "^11.0.1",
"@ngx-translate/http-loader": "^4.0.0"
Plugins:
If anyone has any idea of what it could be I'd really appreciate the help. Been stuck on this for days.
Upvotes: 1
Views: 1416
Reputation: 964
try to add this lines to your config.xml if you are using wkwebview (cordova ios 6.0.0) This can be found in the documentation: https://cordova.apache.org/announcements/2020/06/01/cordova-ios-release-6.0.0.html
<preference name="scheme" value="app" />
<preference name="hostname" value="localhost" />
Upvotes: 1
Reputation: 63
If there's anyone else with the same problem. I solved it by loading my json file and setting the translation manually:
Import your .json file:
import jsonSe from '../assets/i18n/se.json';
Use the translation service to set language manually:
let jsonSeData = (jsonSe as any);
this.translate.setTranslation('se', jsonSeData, true);
Upvotes: 1