简体   繁体   English

ngx-translate 在 iOS 设备 (Cordova) 上不起作用

[英]ngx-translate not working on iOS device (Cordova)

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.我有一个基于 Cordova 的应用程序(非离子),它部署在 android 和 iOS 上。 Everything works fine except that my translations doesn't work on iOS devices (neither simulator or real device).一切正常,除了我的翻译在 iOS 设备(模拟器或真实设备)上不起作用。 I'm using ngx-translate and it there's no problem in the browser or on Android-devices.我正在使用 ngx-translate,它在浏览器或 Android 设备上没有问题。

Here's my setup:这是我的设置:

app.module.ts 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 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.我也尝试过使用其他翻译 styles 像 this.translateService.instant('something'),但它不起作用。

After running cordova build ios I can see that my se.json file is in the correct folder: /assets/i18n/se.json运行 cordova 构建 ios 后,我可以看到我的 se.json 文件位于正确的文件夹中:/assets/i184D4E8DF1B74CFA009913198428ABZ

Version info:版本信息:

"@ngx-translate/core": "^11.0.1",
"@ngx-translate/http-loader": "^4.0.0"
  • 9.0.0 (cordova-lib@9.0.1) 9.0.0 (cordova-lib@9.0.1)
  • ios 5.1.1 ios 5.1.1
  • using WKWebViewOnly使用 WKWebViewOnly
  • allowing all http-intent and http-navigation in config.xml允许 config.xml 中的所有 http-intent 和 http-navigation

Plugins:插件:

  • cordova-plugin-customconfigparameters 3.0.0 "Custom Config Parameters" cordova-plugin-customconfigparameters 3.0.0 “自定义配置参数”
  • cordova-plugin-device 2.0.3 "Device"科尔多瓦插件设备 2.0.3 “设备”
  • cordova-plugin-geolocation 4.0.2 "Geolocation"科尔多瓦插件地理定位 4.0.2 “地理定位”
  • cordova-plugin-splashscreen 5.0.3 "Splashscreen"科尔多瓦插件闪屏 5.0.3 “闪屏”
  • cordova-plugin-whitelist 1.3.4 "Whitelist"科尔多瓦插件白名单 1.3.4 “白名单”
  • cordova-plugin-wkwebview-engine 1.2.1 "Cordova WKWebView Engine" cordova-plugin-wkwebview-engine 1.2.1 “Cordova WKWebView 引擎”
  • onesignal-cordova-plugin 2.9.0 "OneSignal Push Notifications" onesignal-cordova-plugin 2.9.0 “OneSignal 推送通知”
  • skwas-cordova-plugin-datetimepicker 2.1.1 "DateTime picker" skwas-cordova-plugin-datetimepicker 2.1.1 “日期时间选择器”

If anyone has any idea of what it could be I'd really appreciate the help.如果有人知道它可能是什么,我将非常感谢您的帮助。 Been stuck on this for days.被困在这几天了。

If there's anyone else with the same problem.如果还有其他人有同样的问题。 I solved it by loading my json file and setting the translation manually:我通过加载我的 json 文件并手动设置翻译来解决它:

Import your.json file:导入您的.json 文件:

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);

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 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" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM