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
  • @whatever is 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

Command icon 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

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea

Working on this

claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned
Status: Active » Needs review

This 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

dimilias’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

  • claudiu.cristea committed e02a852f on 1.x
    feat: #3577084 Non-translatable placeholders
    
    By: claudiu.cristea
    By:...
claudiu.cristea’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for review

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.