daniel-sc / ng-extract-i18n-merge

Extract and merge i18n xliff translation files for angular projects.
MIT License
173 stars 18 forks source link

Missing <context context-type="linenumber"></context> leads to cryptic error message #110

Open floisloading opened 5 months ago

floisloading commented 5 months ago

Describe the bug After a Pull Request where the XLIFF File was formatted, I got a strange Error message when running ng extract-i18n:

An unhandled exception occurred: Cannot read properties of undefined (reading 'val')
See "/private/var/folders/kd/__0vzmb92fd1f2_k_kxvyrmc0000gn/T/ng-gwLO3C/angular-errors.log" for further details.

and in the angular-errors.log file:

[error] TypeError: Cannot read properties of undefined (reading 'val')
    at /Users/floisloading/Workspace/my-frontend/node_modules/ng-extract-i18n-merge/dist/src/model/translationFileSerialization.js:81:98
    at Array.map (<anonymous>)
    at /Users/floisloading/Workspace/my-frontend/node_modules/ng-extract-i18n-merge/dist/src/model/translationFileSerialization.js:79:18
    at Array.map (<anonymous>)
    at fromXlf1 (/Users/floisloading/Workspace/my-frontend/node_modules/ng-extract-i18n-merge/dist/src/model/translationFileSerialization.js:67:10)
    at fromXlf (/Users/floisloading/Workspace/my-frontend/node_modules/ng-extract-i18n-merge/dist/src/builder.js:78:129)
    at /Users/floisloading/Workspace/my-frontend/node_modules/ng-extract-i18n-merge/dist/src/builder.js:97:47
    at Generator.next (<anonymous>)
    at fulfilled (/Users/floisloading/Workspace/my-frontend/node_modules/ng-extract-i18n-merge/dist/src/builder.js:5:58)

After investigating I found out that both messages.xlf and messages.en.xlf were missing one <context context-type="linenumber"></context> inside one single <context-group>. It got accidentially removed while merging.

In messages.xlf, this works:

      <trans-unit id="8a43db3f950c8e283488f48553c494bbac00ab80" datatype="html">
        <source>Über das Programm</source>
        <note priority="1" from="description">Headline of main info on program detail page</note>
        <context-group purpose="location">
          <context context-type="sourcefile">src/app/program/program-main-info/program-main-info.component.html</context>
          <context context-type="linenumber">8</context>
        </context-group>
      </trans-unit>

while this doesn't:

      <trans-unit id="8a43db3f950c8e283488f48553c494bbac00ab80" datatype="html">
        <source>Über das Programm</source>
        <note priority="1" from="description">Headline of main info on program detail page</note>
        <context-group purpose="location">
          <context context-type="sourcefile">src/app/program/program-main-info/program-main-info.component.html</context>
        </context-group>
      </trans-unit>

Setup/Configuration

"extract-i18n": {
  "builder": "ng-extract-i18n-merge:ng-extract-i18n-merge",
  "options": {
    "buildTarget": "my-frontend:build",
    "format": "xlf",
    "outputPath": "src/i18n",
    "targetFiles": ["messages.en.xlf"],
    "includeContext": true,
    "trim": true,
    "newTranslationTargetsBlank": true
  }
},

Expected behavior

Screenshots none

Version:

Additional information: Source language is de