Search code examples
angularinternationalizationangular6xliffangular8

How to remove location, sourcefile and linenumber from Angular 6's auto generated XLIFF file?


We are using Angular's build in tools to extract messages from templates.

This works fine and we are getting all the information in a XLIFF file using:

ng xi18n

In this file a trans-unit looks like this:

<trans-unit id="3535a6c8296b457542000d2cbd15ca93f86cdd79" datatype="html">
    <source>Homepage</source>
    <context-group purpose="location">
      <context context-type="sourcefile">app/component/nav/nav.component.html</context>
      <context context-type="linenumber">39</context>
    </context-group>
    <note priority="1" from="description">description</note>
    <note priority="1" from="meaning">title</note>
</trans-unit>

Even though the content in <context-group purpose="location"> looks interesting, it exploids project and implementation details to an external translation service.

Is there a way to tell Angular to not include these information into the XLIFF-file?

Alternatively, are there other tools, that could do the transformation? Maybe it's important for the compiler to have that information during a build.


Solution

  • You should not delete those, as Angular needs it to translate.

    But if it's what you want, you can use a JS script to remove them :

    const fs = require('fs');
    const data = fs.readFileSync('./i18n.xliff').toString();
    const contentToRemoveRegexp = /<context-group purpose="location">([.\s\S])*<\/context-group>/g;
    const replaced = data.replace(contentToRemoveRegexp, '');
    fs.writeFileSync('./i18n-updated.xliff', replaced);
    

    store it in whichever JS file you want and make a script in your package file :

    "i18n:update": "ng xi18n && node path/to/your/script/js"