i18n-polyfill icon indicating copy to clipboard operation
i18n-polyfill copied to clipboard

Same internationalized string appearing in both a .ts file and an .html file results in the generated .xlf only specifying source location for the .html instance of the the string

Open Blakesalot opened this issue 5 years ago • 1 comments

If the same internationalized string appears in both a .ts file and an .html file, the resulting .xlf only has a source location reference for the .html.

Repro steps:

  1. Insert the same internationalized string in both a .ts file and an .html file:

example.ts

import { Component } from "@angular/core";
import { I18n } from "@ngx-translate/i18n-polyfill";

@Component({
    selector: "example",
    templateUrl: "./example.html",
})
export class ExampleComponent {

    exampleString = this.i18n("example string");

    constructor(private i18n: I18n) {}
}

example.html

<div i18n>example string</div>
  1. Notice that they each have the same internationalized string "example string"
  2. Run ng xi18n && ngx-extractor -i /src/**/*.ts -f xlf -o .tmp/messages.xlf
  3. Take a look at the generated file: "messages.en-us.xlf"
  4. Observe that only the html source file is listed as a location for the string.
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
  <file source-language="en-us" datatype="plaintext" original="ng2.template" target-language="en-us">
    <body>
      <trans-unit id="5fb0249db474cb03958ca04663b467e9646da391" datatype="html">
        <source>example string</source>
        <target state="final">example string</target>
        <context-group purpose="location">
          <context context-type="sourcefile">example.html</context>
          <context context-type="linenumber">1</context>
        </context-group>
      </trans-unit>
    </body>
  </file>
</xliff>

Blakesalot avatar Sep 17 '18 22:09 Blakesalot

Any progress with this?

JoniJnm avatar Jan 23 '19 14:01 JoniJnm