daniel-sc/ng-extract-i18n-merge

newTranslationTargetsBlank omit does not work

davidyoung77 opened this issue · 4 comments

Describe the bug
When adding new strings for translations with the setting "newTranslationTargetsBlank": "omit", I get the following error
Cannot read property 'attr' of undefined

Setup/Configuration

"extract-i18n-merge": {
          "builder": "ng-extract-i18n-merge:ng-extract-i18n-merge",
          "options": {
            "browserTarget": "digital-intake:build",
            "format": "xlf",
            "includeContext": false,
            "newTranslationTargetsBlank": "omit",
            "outputPath": "apps/digital-intake/src/locale",
            "sourceLanguageTargetFile": "messages.en.xlf",
            "targetFiles": ["messages.en.xlf", "messages.es.xlf"]
          }
        },

If a translate unit doesn't exist this fails

Expected behavior
I expect the new translations to merge without the target element

Screenshots
If applicable, add screenshots to help explain your problem.

Version (please complete the following information):

  • Angular: 13.0.4
  • OS: Mac
  • nodejs: 14.17.0
  • ng-extract-i18n-merge version: 2.0.0 - 2.1.2

Additional context
My translator has requested that I proved the new strings without the target

@daniel-sc I have updated with versions, lmk if you need anymore context

@davidyoung77 I could not reproduce this.

  • Is there any stacktrace coming with the error?
  • Is the error actually going away if you set newTranslationTargetsBlank to true or false?
  • Could you try to reproduce this on Windows or Linux?

Any help appreciated :-)

@daniel-sc I did some debugging and found the issue, it is a versioning problem that you have fixed here https://github.com/daniel-sc/xliff-simple-merge/blob/main/src/merge.ts#L67

The handling of non existent target wasn't in my version, When I updated to the latest version of this lib, it must not have updated simple merge

Old problem code

function resetTranslationState(destUnit, xliffVersion, options) {
    var _a;
    if ((_a = options === null || options === void 0 ? void 0 : options.resetTranslationState) !== null && _a !== void 0 ? _a : true) {
        if (xliffVersion === '2.0') {
            destUnit.childNamed('segment').attr.state = (options === null || options === void 0 ? void 0 : options.sourceLanguage) ? 'final' : STATE_INITIAL_XLF_2_0;
        }
        else {
            destUnit.childNamed('target').attr.state = (options === null || options === void 0 ? void 0 : options.sourceLanguage) ? 'final' : STATE_INITIAL_XLF_1_2;
        }
    }
}```

I will follow up once I update and close, if it looks good.

Thanks again.

Woks as expected now, thanks