daniel-sc / xliff-simple-merge

Merges XLIFF 1.2/2.0 files. Usable for Angular i18n automation.
MIT License
16 stars 7 forks source link

Not copying source to target when "newTranslationTargetsBlank" is true and "sourceLanguage" is also true #9

Closed gergely-gyorgy-both closed 1 year ago

gergely-gyorgy-both commented 1 year ago

Hi!

I would like to generate blank target nodes for every locale, but not the one which is the source language. Currently, using the mentioned options together, in the sourceLanguage locale, I get <target state="final"/>, which is, I think, not the desired behavior. An expected result would be (giving that the source language is in English, other locale is German:

English:

<trans-unit id="test" datatype="html">
        <source>This is the source code text</source>
        <target state="final">This is the source code text</target>
        <note priority="1" from="description">test</note>
</trans-unit>

German:

<trans-unit id="test" datatype="html">
        <source>This is the source code text</source>
        <target state="new"/>
        <note priority="1" from="description">test</note>
</trans-unit>

If you agree, I could make a pull request with the fix.

daniel-sc commented 1 year ago

Hi @gergely-gyorgy-both Do you use this via the command line or as an library? I think the options are available for programmatic/library use (see https://github.com/daniel-sc/xliff-simple-merge/blob/main/src/merge.ts#L4 ) - sourceLanguage: 'en' and newTranslationTargetsBlank: true should be correct. If this combination gives the desired result it is only a matter of integrating these options to the command line interface (PR welcome!). If this does not work, I'll have a closer look.

gergely-gyorgy-both commented 1 year ago

Thanks for responding in such a short time!

Actually, I started to use ng-extract-i18n-merge, where I have the following config:

"extract-i18n": {
                    "builder": "ng-extract-i18n-merge:ng-extract-i18n-merge",
                    "options": {
                        "browserTarget": "reponame:build",
                        "format": "xlf",
                        "outputPath": "locale",
                        "targetFiles": [
                            "messages.de-DE.xlf",
                            "messages.en-US.xlf"
                        ],
                        "sourceFile": "/messages.xlf",
                        "sourceLanguageTargetFile": "messages.en-US.xlf",
                        "fuzzyMatch": false,
                        "trim": true,
                        "newTranslationTargetsBlank": true
                    }
}

I just run ng extract-i18n. I would like to have blank target nodes in the messages.de-DE.xlf file with "new" state (this can be achieved with the newTranslationTargetsBlank set to true), but also would like to copy the source as target nodes in messages.en-US.xlf (and mark them as final). I started some digging in that code, and noticed that this project is responsible for generating the target files. I actually even made a fix, I just don't really know that is it a valid use case what I'm doing.

If I misunderstood something, please feel free to ask.

daniel-sc commented 1 year ago

ok - this is what I'd expect with the given configuration as well - are you using the latest version? What is the actual output?

daniel-sc commented 1 year ago

but if you spotted the/a bug in the code already, please make a PR - there a discussion can be more specific :)