角度i18n翻译在生产中不起作用

时间:2018-04-24 15:48:53

标签: angular angular5 angular-i18n

在我的开发环境中,代码运行正常。但是一旦我构建它并推向生产,它就无法将应用程序编译成正确的语言

console.log(environment);

if (environment.production) {
   enableProdMode();
   window.console.log = function () { };   // disable any console.log debugging statements in production mode
}


declare const require;
var translations;

let locationSplit = window.location.hostname.split(".");
console.log(locationSplit);

if (locationSplit[0] == environment.chinese) {

  translations = require(`raw-loader!./locale/translatedChinese.zh-Hans.xlf`);
}
else {

  translations = null;
}


platformBrowserDynamic().bootstrapModule(AppModule, {
  providers: [
    { provide: TRANSLATIONS, useValue: translations },
    { provide: TRANSLATIONS_FORMAT, useValue: 'xlf' }
  ]
});

我控制台记录了翻译文件,并在那里。但是......它没有这样做。是的,逻辑很好。我测试了它。就像我说的,当用webpack在本地运行时,一切都很顺利。所以我对这个问题感到困惑。文件在那里,逻辑是正确的,但它仍然以英文显示:(

2 个答案:

答案 0 :(得分:0)

角度i18n不适用于aot。尝试像这样建立确保关闭:

 ng build --aot=false

答案 1 :(得分:-1)

看看这个:https://angular.io/guide/i18n#merge-with-the-aot-compiler 使用AOT编译器似乎可以做到这一点。

相关问题