Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XLIFF 2 files generated by Angular i18n tooling are not parsed #24315

Closed
ghost opened this issue Jun 6, 2018 · 2 comments
Closed

XLIFF 2 files generated by Angular i18n tooling are not parsed #24315

ghost opened this issue Jun 6, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Jun 6, 2018

Being new to Angular, I was testing I18n functionalities following the official guide and was comparing XLIFF 1.2 and XLIFF 2.0.

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

Expected behavior

The app home page requires two translations.

Using XLIFF 1.2 file with ng serve --configuration=fr-1.2 runs without error as showned in the official guide. However running using XLIFF 2.0 file with ng serve --configuration=fr-2.0 triggered warning:

Missing translation for message "homepage.title"
Missing translation for message "homepage.sentence"   

Obviously, changing the i18nMissingTranslation from warning to error triggers a similar error:

ERROR in Missing translation for message "homepage_title" ("
</div>

<h2 i18n="@@homepage_title">[ERROR ->]Title</h2>

<p i18n="@@homepage_sentence">This is a sentence</p>
"): [...]/angular-i18n/src/app/app.component.html@8:28

Minimal reproduction of the problem with instructions

Short version

Stackblitz does not support .xlf file but source code is available at https://github.com/Xsylum/angular-i18n. Use ng serve --configuration=fr-2.0 to trigger the warning.

Description

The two required translations are:

app.component.html

<h2 i18n="@@homepage.title">Title</h2>
<p i18n="@@homepage.sentence">This is a sentence</p>

I wanted to compare XLIFF 1.2 and XLIFF 2.0 format. To do so, three .xlf messages were generated.

  1. messages.xlf generated by
    ng xi18n --i18n-format=xlf --out-file messages.xlf --i18n-locale=en
  2. messages.xlf12.fr.xlf generated by
    ng xi18n --i18n-format=xlf --out-file messages.xlf12.fr.xlf --i18n-locale=fr
    Due to ng xi18n Xliff no longer produces empty <target/> translations causing the Xliff parser to fail #21690, <target> was manually added:
    <?xml version="1.0" encoding="UTF-8" ?>
    <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
      <file source-language="en" target-language="fr" datatype="plaintext" original="ng2.template">
        <body>
          <trans-unit id="homepage.title" datatype="html">
            <source>Title</source>
            <target>Titre</target>
            <context-group purpose="location">
              <context context-type="sourcefile">app/app.component.ts</context>
              <context context-type="linenumber">9</context>
            </context-group>
          </trans-unit>
          <trans-unit id="homepage.sentence" datatype="html">
            <source>This is a sentence</source>
            <target>Ceci est une phrase</target>
            <context-group purpose="location">
              <context context-type="sourcefile">app/app.component.ts</context>
              <context context-type="linenumber">11</context>
            </context-group>
          </trans-unit>
        </body>
      </file>
    </xliff>
  3. messages.xlf2.fr.xlf generated by
    ng xi18n --i18n-format=xlf2 --out-file messages.xlf2.fr.xlf --i18n-locale=fr
    <target> also manually added. srcLang and trgLang manually edited.
    <?xml version="1.0" encoding="UTF-8" ?>
    <xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en" trgLang="fr">
      <file original="ng.template" id="ngi18n">
        <unit id="homepage.title">
          <notes>
            <note category="location">app/app.component.ts:9</note>
          </notes>
          <segment>
            <source>Title</source>
            <target>Titre</target>
          </segment>
        </unit>
        <unit id="homepage.sentence">
          <notes>
            <note category="location">app/app.component.ts:11</note>
          </notes>
          <segment>
            <source>This is a sentence</source>
            <target>Ceci est une phrase</target>
          </segment>
        </unit>
      </file>
    </xliff>

Configurations have been adjusted accordingly:

    "configurations":{
        "fr-1.2": {
          "aot": true,
          "i18nFile": "src/messages.xlf12.fr.xlf",
          "i18nFormat": "xlf",
          "i18nLocale": "fr",
          "i18nMissingTranslation": "warning"
        },
        "fr-2.0": {
          "aot": true,
          "i18nFile": "src/messages.xlf2.fr.xlf",
          "i18nFormat": "xlf",
          "i18nLocale": "fr",
          "i18nMissingTranslation": "warning"
        },
        "production": "..."
    }

serve is adjusted with the same names.

What is the motivation / use case for changing the behavior?

Starting a new Angular project, I was hesitating between using Angular I18n or ngx-translate. Reading ngx-translate/core#495 led me to try Angular I18n. While checking XLIFF format, it appears that XLIFF 1.2 is pretty old, almost 10 years old and that XLIFF 2+ is not retrocompatible with XLIFF 1.2 (Source: slide#6).

However, I did not find so many free tools supporting XLIFF 2+ so I might start my project under XLIFF 1.2 hoping that if we need to migrate to XLIFF 2+, it won't be too hurtful.

I report this as a bug as I assumed that the I18n tooling can generate files that Angular can use 😄

Environment


Angular CLI : 6.0.7
Node        : 8.11.2
OS          : win32 x64 => Windows 10 (version 1803 build 17134.48)
Angular     : 6.0.3
Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.6.7
@angular/cli                      6.0.7
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.7
@schematics/update                0.6.7
typescript                        2.7.2
webpack                           4.8.3


Browser:
- [x] Chrome (desktop) version 66.0.3359.181 x64
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [x] Firefox version 60.0.1 x64
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

Others:

@ghost
Copy link
Author

ghost commented Jun 6, 2018

Okay... sometimes it's good to write issue as it gives another way of thinking about the problem. Angular does indeed support XLIFF 2.0: the i18nFormat must be xlf2 instead of xlf.

            "fr-2.0": {
              "aot": true,
              "i18nFile": "src/messages.xlf2.fr.xlf",
              "i18nFormat": "xlf2",
              "i18nLocale": "fr",
              "i18nMissingTranslation": "warning"
            }

Apologies for irrelevant issue

@ghost ghost closed this as completed Jun 6, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 2, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants