leolabs / json-autotranslate

Translate a folder of JSON files containing translations into multiple languages.
MIT License
139 stars 41 forks source link

Interpolation positions are broken when translating from/to certain languages (e.g. de>it) #123

Open codeflorist opened 1 month ago

codeflorist commented 1 month ago

I'm performing translations via DeepL Free API. Here is the command:

npx json-autotranslate --source-language de --directory-structure ngx-translate  --type key-based  --decode-escapes --service deepl-free --config API_KEY

I have a de.json like this:

{
  "confirmation": "Ich habe {privacyPolicy} und {terms} gelesen und akzeptiert."
}

Translating this to en correctly translates the string to:

"I have read and accepted {privacyPolicy} and {terms}."

But translating to it (and most other languages) results in the interpolations being placed at the start of the term instead of their original positions:

"{privacyPolicy} {terms} Ho letto e accettato e ."

The problem does not occur, if the source language is en. So first translating from de to en, and then using the english file to translate to the other languages seems to be a viable workaround.