ng xi18n: exclude code in node_modules when extracting strings
Asked Answered
S

0

10

In our Angular app, we are using the Angular i18n mechanism to mark strings as translatable in the component-HTML and we use ng xi18n to extract the translatable strings and write them to a xlf file. But besides of our app strings the xlf file does also contain strings from the ng-bootstrap library which we use in our app and which has all of its code in the node_modules folder.

The following xml block is an example which shows one of the strings, we don't want to have in our messages.xlf, but which is also extracted by the ng xi18n tool:

...
<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>
...

Is there a way to not have stuff from node_modules included in the extracted strings? Like some exclude option which can be configured in some place? I could not find anything alike on google, but I wanted to ask here before opening a bug request on the angular-cli github project...

Further detail:

A simple way to reproduce this problem is given with the following steps:

  • Create a new Angular app
  • Add the line @ng-bootstrap/ng-bootstrap": "^5.2.1" to package.json and run npm install
  • Add NgbModule to the imports section in app.module.ts
  • Replace the content in app.component.html by a simple <div i18n>example text</div>
  • run ng i18n
  • Look at the generated messages.xlf
    • You see the "example text" from app.component.html
    • And you see all the strings from ng-bootstrap
Shekinah answered 6/2, 2020 at 13:10 Comment(2)
This was now proposed to the Angular team as a new feature and is tracked in Github under github.com/angular/angular/issues/35223. If this feature is part of any official Angular release at some point in the future I will update this question accordingly.Shekinah
any way to solve this?Colatitude

© 2022 - 2024 — McMap. All rights reserved.