生成xlf文件时Webpack Extracti18nplugin问题

时间:2017-11-28 03:36:35

标签: angular internationalization

使用i18n进行jit国际化,并使用webpack Extracti18nplugin在提取阶段获取错误

package.json 

"angular/common": "~5.0.0",
"angular/compiler": "~5.0.0",
"angular/core": "~5.0.0",
"angular/forms": "~5.0.0",
"angular/cli": "^1.5.4",
"angular/compiler-cli": "~5.0.0",

Error: Please update @angular/cli. Angular 5+ requires at least Angular CLI 1.5+
    at throwNotSupportedError (C:\Trunk\WebClientNew\node_modules\@angular\compiler-cli\src\ngtools_api.js:78:11)
    at Function.NgTools_InternalApi_NG_2.extractI18n (C:\Trunk\WebClientNew\node_modules\@angular\compiler-cli\src\ngtools_api.js:72:15)
    at _donePromise.Promise.resolve.then (C:\Trunk\WebClientNew\node_modules\@ngtools\webpack\src\extra

1 个答案:

答案 0 :(得分:0)

现在似乎不再需要<span class="Icon chevron-up-circle" style="display: inline-block; width: 1.12rem; height: 1.12rem;"> <svg enable-background="new 0 0 33 33" version="1.1" viewBox="0 0 33 33" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <g id="Chevron_Up_Circle"><circle cx="16" cy="16" r="15" stroke="#121313" fill="none"></circle> <path d="M16.699,11.293c-0.384-0.38-1.044-0.381-1.429,0l-6.999,6.899c-0.394,0.391-0.394,1.024,0,1.414 c0.395,0.391,1.034,0.391,1.429,0l6.285-6.195l6.285,6.196c0.394,0.391,1.034,0.391,1.429,0c0.394-0.391,0.394-1.024,0-1.414 L16.699,11.293z" fill="#121313"></path> </g> </svg> </span> ExtractI18nPlugin现在支持其功能 - 请参阅新标记AngularCompilerPlugini18nOutFile。此外,用于构建本地化应用的旧i18nOutFormati18nFile标记已分别重命名为i18nFormati18nInFile

这意味着现在在主AOT编译阶段提取字符串,而不是由i18n提取插件启动的额外编译过程。只需从配置中删除i18nInFormat,然后将新标记添加到ExtractI18nPlugin

示例:

AngularCompilerPlugin

注意new AngularCompilerPlugin({ tsConfigPath: "tsconfig.json", entryModule: "Scripts/app/app.module.ts#AppModule", i18nInFile: "./Resources/Locale/messages.de.xlf", i18nInFormat: "xlf", locale: "de", i18nOutFile: "./Resources/Locale/messages.xlf", i18nOutFormat: "xlf" }), 总是执行AOT编译,因此对于i18n提取阶段没有JIT编译这样的东西。

更新:我刚刚注意到,当设置了字符串提取的ng xi18n参数时,Webpack会静默失败并输出0字节文件而不是应用程序包。您不能一次激活上述示例中的所有选项。换句话说,i18nOut现在处理字符串提取和编译,但不支持同时执行这两种操作。

由于AngularCompilerPlugin的文档不存在,我通过查看插件的源代码(特别是this commit)发现了这一点。我不是这方面的权威,但似乎计划从Angular 5开始弃用@ngtools/webpack而不是ExtractI18nPlugin(他们只是没有告诉任何人)。您获得的错误消息当然是错误的(我在尝试使用AngularCompilerPlugin时也得到了它),但似乎Angular 5项目不再支持该插件。