当我使用aot进行生产并进行buildOptimize时,我的xlf i18n停止工作

时间:2019-07-05 15:59:27

标签: angular internationalization translation angular-aot

我将xlf加载到main.ts中,但看不到为每种语言进行单独构建的意义。这在ng serveng build中有效,但在我做aot和buildOptimizer时不适用。

如果我将这些属性添加到angular.json生产版块中,则它适用于de,但是我无法更改语言

"i18nFile": "src/assets/locale/de.lproj/tables.xlf",
"i18nFormat": "xlf",
"i18nLocale": "de",
"i18nMissingTranslation": "error",

main.ts

import { enableProdMode, TRANSLATIONS, TRANSLATIONS_FORMAT, MissingTranslationStrategy } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
  enableProdMode();
}

// use the require method provided by webpack
declare const require;
// we use the webpack raw-loader to return the content as a string
const translations = require('raw-loader!./assets/locale/' + document['locale'].substr(0, 2) + '.lproj/tables.xlf');

platformBrowserDynamic().bootstrapModule(AppModule, {
  missingTranslation: MissingTranslationStrategy.Warning, // this can be set to error so you can check if all translations exist in xlf, but you have to remove 2 i18n tags from fields/input/input.component.html
  providers: [
    {provide: TRANSLATIONS, useValue: translations},
    {provide: TRANSLATIONS_FORMAT, useValue: 'xlf'}
  ]
})
  .catch(err => console.error(err));

我希望它以生产模式(如ng build或serve-mode)加载xlf。如果我查看main.9ca....,则所有4个xlf都将像这样加载:

  

(window.webpackJsonp = window.webpackJsonp || [])。push([[4],{0:function(e,t,r){e.exports = r(“ zUnb”)}},NL8Z:函数(e,t){e.exports ='

因此,似乎webpack包含了它,但它不起作用。

0 个答案:

没有答案