在我们的 Angular 应用程序中,我们使用 Angular i18n 机制在组件 HTML 中将字符串标记为可翻译,并ng xi18n用于提取可翻译字符串并将它们写入 xlf 文件。但是除了我们的应用程序字符串之外,xlf 文件还包含来自 ng-bootstrap 库的字符串,我们在我们的应用程序中使用了它,并且它的所有代码都在 node_modules 文件夹中。
下面的 xml 块是一个示例,它显示了一个字符串,我们不希望在我们的 messages.xlf 中有,但它也被ng xi18n工具提取:
...
<trans-unit id="ngb.alert.close" datatype="html">
<source>Close</source>
<context-group purpose="location">
<context context-type="sourcefile">node_modules/@ng-bootstrap/ng-bootstrap/alert/alert.d.ts</context>
<context context-type="linenumber">3</context>
</context-group>
</trans-unit>
...
Run Code Online (Sandbox Code Playgroud)
有没有办法在提取的字符串中不包含来自 node_modules 的内容?像一些可以在某个地方配置的排除选项?我在 google 上找不到任何类似的东西,但我想在打开 angular-cli github 项目上的错误请求之前先在这里问一下......
更多细节:
通过以下步骤给出了重现此问题的简单方法:
@ng-bootstrap/ng-bootstrap": "^5.2.1"将这一行添加到 package.json 并运行 npm install<div i18n>example text</div>