小编tko*_*sta的帖子

ng xi18n:在提取字符串时排除 node_modules 中的代码

在我们的 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 项目上的错误请求之前先在这里问一下......

更多细节:

通过以下步骤给出了重现此问题的简单方法:

  • 创建一个新的 Angular 应用
  • @ng-bootstrap/ng-bootstrap": "^5.2.1"将这一行添加到 package.json 并运行 npm install
  • 将 NgbModule 添加到 app.module.ts 的导入部分
  • 用一个简单的替换 app.component.html 中的内容 <div i18n>example text</div>
  • 运行 ng i18n
  • 查看生成的messages.xlf
    • 您会看到 app.component.html 中的“示例文本”
    • 你会看到 ng-bootstrap …

angular-cli angular-i18n angular

6
推荐指数
0
解决办法
604
查看次数

标签 统计

angular ×1

angular-cli ×1

angular-i18n ×1