Problem/Motivation
Sometimes parts of a text sent for translation should remain unchanged, especially text placeholders. eTranslation has some policies about what should not be translated but it's very limited.
In some languages (such as Bulgarian), I've observed some behaviors but I'm not sure I can draw a generic rule. And even if I would, I cannot see how to solve the issue. Here are some limited findings (I've used Bulgarian to illustrate):
<a href="@entity:url">- placeholder is preserved because it's inside an HTML tag@whateveris preserved@entity:bundle->@entity: пакет- added a space after colon and translated the 2nd word@actor:field_user_first_name->@actor: field_user_first_name- added a space after colon but didn't translate the 2nd word because, presumably, contains an underscore"@entity:title"->„@entity: title“- added a space after colon but didn't translate the 2nd word, presumably, because the whole placeholder is wrapped inside double quotes[user:account-name]->[user: account-name]- added a space after colon but it didn't translate the 2nd word, presumably, because contains a dash (?)<a href="[site:url]">- preserved because it's inside an HTML tag[site:url]->[сайт: URL]:(
I'm sure there a lot of other cases but not all target languages are behaving the in same way. I saw languages that are preserving better some placeholders but can we rely?
Proposed resolution
Any ideas are welcomed.
For the beginning, what comes in my mind, is a new plugin setting to store a list of regular expressions. This is configurable in the plugin settings form, site builders are able to maintain this list per translator entity. Each regex matches strings that should be preserved during the translation. Before making the request we run all regexps against the text to be sent and replace each match by wrapping it inside [notranslate] tag. Pieces of text wrapped in this tag are not translated by eTranslation, see https://language-tools.ec.europa.eu/dev-corner/additional-resources/tips...
For instance, one regexp could be /([@!%][a-zA-Z0-9:_-]+)/. This will transform, just before sending to eTranslation, a text like...
The @entity:bundle item
into...
The [notranslate]@entity:bundle[/notranslate] item
On receiving back the translation, it might need to remove the [notranslate] tag
Remaining tasks
Decide about the approach.
User interface changes
API changes
Data model changes
Issue fork tmgmt_ec_etranslation-3577084
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
claudiu.cristeaComment #3
claudiu.cristeaComment #4
claudiu.cristeaWorking on this
Comment #6
claudiu.cristeaThis is ready for review.
The "phpunit (next minor)" job failure is not related and is failing also in the branch. I've created #3578229: The "phpunit (next minor)" job is failing
Comment #7
dimilias commentedI personally don't prefer the way the string patterns are constructed but we had a discussion with @claudiucristea and I am fine with the logic. I have tested the ticket in our project and works nicely.
Comment #9
claudiu.cristeaThank you for review