-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Hello! I'm seeing some strange translations when using the DeepL API with xml tags. The tags are just used to map the result back to the original text.
Here's a simple Swedish string that can be used to reproduce the problem: <x key="0">Köpesumma</x>. It should translate to Purchase amount.
$this->client = new \DeepL\Translator(config('services.deepl.api.key'));
$translated = collect(
$this->client->translateText(
['<x key="0">Köpesumma</x>'],
'sv',
'en-US',
[
TranslateTextOptions::TAG_HANDLING => 'xml',
TranslateTextOptions::PRESERVE_FORMATTING => false,
TranslateTextOptions::FORMALITY => 'prefer_less',
]
)
)After looking through the code I found that the following form data was generated for cURL: target_lang=en-US&source_lang=sv&formality=prefer_less&text=%3Cx+key%3D%220%22%3EKopesumma%3C%2Fx%3E&preserve_formatting=0&tag_handling=xml
And the following response was returned via the library:
{
"translations": [
{
"detected_source_language": "SV",
"text": "<x+key=\"0\">Copayment</x>"
}
]
}...which is incorrect! If I manually call the API and use JSON to post the data, it works as expected:
Input:
{
"text": [
"<x key=\"0\">Köpesumma</x>"
],
"target_lang": "en-US",
"source_lang": "sv",
"formality": "prefer_less",
"preserve_formatting": false,
"tag_handling": "xml"
}Response:
{
"translations": [
{
"detected_source_language": "SV",
"text": "<x key=\"0\">Purchase price</x>"
}
]
}...which is correct! I'm not sure if there is a problem with the library or if I'm using it incorrectly?