Skip to content

Carriage returns disappear from translations #123

Description

@peurKe

Hi,
I'm having a problem managing \r and \n CARRIAGE RETURN characters.
I want to translate sentences containing CARRIAGE RETURN characters that can be located right in the middle of sentences.

I use the following parameters to ask DeepL not to take CARRIAGE RETURN characters into account:

import deepl
translator = deepl.Translator('my_auth_key')

text = "Отпустите рюкзак\r\nи он автоматически\r\nвернется на место"
translation = translator.translate_text(
        text,
        source_lang=deepl.Language.RUSSIAN,
        target_lang=deepl.Language.ENGLISH_AMERICAN,
        formality=deepl.Formality.PREFER_LESS,
        split_sentences=deepl.SplitSentences.NO_NEWLINES,
        # preserve_formatting=True  # Doesn't help, even when uncommented 
    ).text

The meaning of the translations via the API with the DeepL python library are correct but I lose the CARRIAGE RETURN characters in the results (I have also tried with preserve_formatting=True but no better)
I tried with \n instead of \r\n but same results too.

text          : 'Отпустите рюкзак\r\nи он автоматически\r\nвернется на место'
translation   : 'Let go of the backpack and it will automatically return to its place'

text          : 'Отпустите рюкзак\nи он автоматически\nвернется на место'
translation   : 'Let go of the backpack and it will automatically return to its place'

Here's what I expect to happen:

text          : 'Отпустите рюкзак r\nи он автоматически\r\nвернется на место'
translation   : 'Let go of the backpack\r\nand it will automatically\r\nreturn to its place'

text          : 'Отпустите рюкзак\nи он автоматически\nвернется на место'
translation   : 'Let go of the backpack\nand it will automatically\nreturn to its place'

Am I doing something wrong?
Thanks in advance

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions