Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate string literals with programming logic #41

Open
Juanca24691 opened this issue Dec 15, 2023 · 2 comments
Open

Translate string literals with programming logic #41

Juanca24691 opened this issue Dec 15, 2023 · 2 comments

Comments

@Juanca24691
Copy link

Currently I am developing a tool that extracts all string literals that are enclosed in double quotes from a file, the problem is that these string literals have programming logic as escape sequences and Deepl is not able to maintain that logic, this is an example of a string literal containing Russian characters that I want to translate into Spanish

"{ffffff}Дом {ffff00}№%d\n
{ffffff}Стартовая цена аукциона: {ffff00}%d BTC\n
{ffffff}Минимальная ставка: {ffff00}%d BTC\n
Завершение аукциона через: {ffff00}%s\n\n
{cccccc}%s - %d BTC\n\n
{ffffff}Укажите сумму вашей ставки:"

How should I approach this situation?

@daniel-jones-deepl
Copy link
Member

daniel-jones-deepl commented Dec 15, 2023

Hi @Juanca24691, thanks for the question.

For tags like these you are best to use XML tag handling -- the DeepL API handles these tags carefully not to translate their content. We have an example translating Mustache templates in our Python library using this technique. That example might be useful to you.

Summarised: you could parse the strings and replace the {} tags with XML tags, putting their content in an attribute. Additionally you may need to replace the %... and \n sequences too. For example:

{ffffff}Дом {ffff00}№%d\n
{ffffff}Стартовая цена аукциона: {ffff00}%d BTC\n

would become:

<x c="{ffffff}" />Дом <x c="{ffff00}" />№<x c="%d\n" />
<x c="{ffffff}" />Стартовая цена аукциона: <x c="{ffff00}%d" /> BTC<x c="\n" />

Translate that string to Spanish with tag handling="xml", to get something like:

<x c="{ffffff}" />Casa <x c="{ffff00}" />#<x c="%d\n" />
<x c="{ffffff}" />Precio de salida de la subasta: <x c="{ffff00}%d" /> BTC<x c="\n" />

Then you can replace the tags with their original content:

{ffffff}Casa {ffff00}#%d\n
{ffffff}Precio de salida de la subasta: {ffff00}%d BTC\n

I hope that helps, let me know if you have more questions.

@Juanca24691
Copy link
Author

I have implemented it but Deepl adds extra characters that it shouldn't, for example XML tag closures sometimes add an extra closure like this /> or in some cases when there is a symbol like this | deepl adds one more ||

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants