【问题标题】:Ionic 3 i18n translation on iOS WKWebviewiOS WKWebview 上的 Ionic 3 i18n 翻译
【发布时间】:2020-09-13 03:46:19
【问题描述】:

升级到 WKWebview 后,我无法从 .json 文件中获取翻译数据。它在浏览器中运行得很好,但是当我将它部署到设备中时,它就不起作用了。

我的 app.module.ts

import {
  HttpClientModule,
  HttpClient,
  HTTP_INTERCEPTORS
} from "@angular/common/http";
import { TranslateModule, TranslateLoader } from "@ngx-translate/core";
import { TranslateHttpLoader } from "@ngx-translate/http-loader";
@NgModule({
  declarations: [
    MyApp,
    PopoverComponent,
    LimitToDirective,
    ImageModalPage,
    PaymentPage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    HttpModule,
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: createTranslateLoader,
        deps: [HttpClient]
      }
    }),
    FormsModule,
    IonicImageLoader.forRoot()
  ],
  bootstrap: [IonicApp],
  entryComponents: [
   ...

  ],
  providers: [
    ...
  ]
})

export class AppModule {}

export function createTranslateLoader(http: HttpClient) {

  return new TranslateHttpLoader(http, "assets/i18n/", ".json");
}

翻译init方法

 initTranslate() {
    this.translate.use("en");
  }

调用方法

<div class="primaryLabel">{{ "commons.version" | translate }}</div>
translate.get("commons").subscribe(val => {
      console.log(val)
      this.headerTitle = val.title;
    });

我的 en.json 文件

{
"commons": {
        "title": "XXXXX",
        "logout": "Logout",
        "confirmLogout": "Are you sure you want to logout ?",
        "currency": "SAR",
        "version": "Version",
        "updateProfile": "Update Profile",
        "faq": "FAQ"
    }
}

console.log(val) 将输出作为“commons”。

【问题讨论】:

标签: angular typescript cordova ionic-framework


【解决方案1】:

cordova-plugin-wkwebview-file-xhr 插件添加到您的项目中,它应该会再次工作:

ionic cordova plugin add cordova-plugin-wkwebview-file-xhr

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-27
    • 1970-01-01
    • 1970-01-01
    • 2012-11-12
    • 1970-01-01
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    相关资源
    最近更新 更多