ngx-translate不适用于Ionic 3 Angular 5

时间:2018-03-19 05:50:12

标签: angular ionic-framework ionic3 angular5 ngx-translate

我使用离子3在Angular 5中创建了一个应用程序,但ngx-translate未正确加载。我在每一页都使用了延迟加载。

app.module.ts

import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import {HttpClientModule, HttpClient} from '@angular/common/http';
export function createTranslateLoader(http: HttpClient) { 
    console.log("TranslateLoader");
    return new TranslateHttpLoader(http, './assets/i18n', '.json');
}
imports: [
HttpClientModule,
......
TranslateModule.forRoot({
  loader: {
    provide: TranslateLoader,
    useFactory: (createTranslateLoader),
    deps: [HttpClient]
  }
}),
.....
]

app.component.ts

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, public translate: TranslateService) {
    this.initTranslate();
    platform.ready().then(() => {
        // Okay, so the platform is ready and our plugins are available.
        // Here you can do any higher level native things you might need.
        console.log("Loaded Page");
        statusBar.styleDefault();
        splashScreen.hide();
    });
}
initTranslate() {
    this.translate.addLangs(["en", "hi"]);
    this.translate.setDefaultLang('en');
    this.translate.use('en');

    this.translate.get("HOME").subscribe((res: string) => {
        console.log(res);
    });
}

en.json

{
    "HOME":"Home"
}

正如我的json所说,我的日志应打印Home,但打印HOME。指出我在做什么错误?

0 个答案:

没有答案