开始使用angular2s rc6 i18n,我想运行ng-xi18n脚本来提取相应的i18n属性以便进一步处理。
然而,脚本失败并显示
之类的消息/project ❯❯❯ npm run extract
> test.com@0.0.1 extract C:\project
> ng-xi18n
Error: Compilation failed. Resource file not found: C:/project/src/styles/colors
at Object.resourceLoader.get (C:\project\node_modules\@angular\compiler-cli\src\extract_i18n.js:127:27)
at DirectiveNormalizer._fetch (C:\project\node_modules\@angular\compiler\bundles\compiler.umd.js:13450:45)
at C:\project\node_modules\@angular\compiler\bundles\compiler.umd.js:13552:55
at Array.map (native)
at DirectiveNormalizer._loadMissingExternalStylesheets (C:\project\node_modules\@angular\compiler\bundles\compiler.umd.js:13552:16)
at C:\project\node_modules\@angular\compiler\bundles\compiler.umd.js:13555:28
at process._tickCallback (node.js:382:9)
at Function.Module.runMain (module.js:433:11)
at startup (node.js:141:18)
at node.js:977:3
TypeError: Cannot read property 'write' of undefined
at C:\project\node_modules\@angular\compiler-cli\src\extract_i18n.js:34:46
at process._tickCallback (node.js:382:9)
at Function.Module.runMain (module.js:433:11)
at startup (node.js:141:18)
at node.js:977:3
Extraction failed
显然,脚本找不到文件C:/ project / src / styles / colors,这是完全正确的,因为这是一个sass partial,因此被命名为_colors并在styleUrls中使用的组件自己的sass文件中引用: []
我可以将脚本限制为仅调查特定文件(例如所有* .ts)或为什么要调查我的样式表?
如果调查样式表文件是有效的,那么脚本似乎不知道sass部分语法。
我使用webpack捆绑和处理styleUrls中的sass文件引用:[]在我生成的文件中内联。但这不应该是一个问题,因为ng-xi18n正在未捆绑的源上运行。
任何提示都表示赞赏。 THX。
答案 0 :(得分:1)
我最近遇到了同样的问题。为了使.scss
能够让我翻译消息包,我只需用空字符串替换./node_modules/.bin/ng-xi18n -p src/tsconfig.json
个文件中的所有ng-xi18n
,并执行{{1}},如{{3}所述}}。
你问过,为什么要调查你的样式文件......这是因为{{1}}分析了任何模块的组件附件,这个过程需要编译组件并解析组件的样式导入...偶尔,它解决它们无效......
答案 1 :(得分:1)
使用Angular CLI创建翻译源文件就像魅力一样:
ng xi18n