How to handle newline characters in translated text?

1k Views Asked by At

I'm using Custom translator to translate Russian text into English. Some sentences contain \n character that means newline. And my goal is to translate the text like there are no newlines in it, but I want to preserve this \n.

Example russian:

очередь, к которой отнесен обработчик и в которой зарегистрированы данные, которые он будет обрабатывать.

English translation:

queue to which the handler is assigned and in which the data that it will process is registered

This text can have \n in different places:

очередь, к которой отнесен обработчик и в которой зарегистрированы данные, которые он будет\nобрабатывать. очередь, к которой отнесен обработчик и в которой зарегистрированы данные\n которые он будет обрабатывать. очередь, к которой отнесен обработчик и в которой\nзарегистрированы данные, которые он будет обрабатывать.

And all translations should match the first one, but preserving the '\n' position.

Is it possible? I've tried to replace \n with <BR> or with &nbsp; but the translation is different.

2

There are 2 best solutions below

2
On

I could not find an elegant way of doing it. But, found a workaround. You can replace the "\n" with some word or characters from a completely different script and the translator keep it as it is, without having any effect on the translation. After you get back the translated text you can replace your dummy word with "\n".

I translated

очередь, к которой отнесен обработчик и в которой зарегистрированы данные, которые он будет मुखपृष्ठ обрабатывать. очередь, к которой отнесен обработчик и в которой зарегистрированы данные मुखपृष्ठ которые он будет обрабатывать. очередь, к которой отнесен обработчик и в которой मुखपृष्ठ зарегистрированы данные, которые он будет обрабатывать.

and it gave me

the queue to which the handler is assigned and where the data that it will मुखपृष्ठ process is recorded. the queue to which the handler is assigned and in which the data मुखपृष्ठ which it will process is recorded. the queue to which the handler is assigned and in which the मुखपृष्ठ recorded the data that it will process.

Here I have used a "hindi" word "मुखपृष्ठ" but you can probably try with something like Japanese or something.

Just to repeat, this is just a workaround that I have found to be working at this moment, don't know if this is good enough for all kinds of use cases or if it continue to work in future.

0
On

Wow! Found the solution!
Need to replace \n with <b> </b>