To test:

  • Install a second language and make Article translatable.
  • Add a field ie field_color
  • Create a pattern, ie "This article is [node:field_color:value]
  • Create an article with Blue
  • Translate Blue in the second language
  • The result is: This article is Azul instead of Este articulo esta Azul
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

parijke created an issue. See original summary.

colan’s picture

mandclu’s picture

I was able to make some progress on this by editing AutoEntityLabelManager->generateLabel() on line 292, changing:

    $output = $this->token->replace($pattern,

to:

    $output = $this->token->replace($this->t($pattern),

That does allow the pattern to be translated, but saving in any language seems to save the title as generated in the current language (current language pattern and current language tokens) to all translations. So still needs some work to only save the title for the current language.

mandclu’s picture

Status: Active » Needs review
StatusFileSize
new618 bytes

Turns out, the secondary issue was that I had forgotten to configure the title to be translatable. Once I did that, it worked as expected. Here's a patch.

DeaOm made their first commit to this issue’s fork.

deaom’s picture

The t() wants the first argument to be an actual string, not a variable, as it otherwise gives a notice of "Only string literals should be passed to t() where possible". It is working with the $this->t($pattern), so not sure about the notice/warning here.
Did play around with different possibles and finally decided with the committed one, so the @pattern is added as an argument which can then be translated via UI. If I follow the provided example, the source string would be @pattern and then translation string is the actual pattern translated: Este articulo esta [node:field_color:value]
Did add an "explanation" to the description part for the pattern. This is like a small workaround, as I think the form or at least the pattern part should probably be made translatable via config translation.

minoroffense’s picture

I'm not sure this patch is required. If you just copy your auto_entitylabel.settings.*.yml file into config/sync/language/fr for example, update the pattern and import it translates the title properly. Mind you there's no UI to allow you to do this so that may be where the patching effort should go.

igork96’s picture

Version: 8.x-3.0-beta2 » 8.x-3.x-dev
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.49 KB

I tested the solution from #6 and MR that is created and can confirm that is working. When you translate the pattern in User interface translation search for @pattern and you need to enter the token there in the translation "Este articulo esta [node:field_color:value]"

  • VladimirAus committed cd3b386f on 8.x-3.x authored by igork96
    Issue #3096803 by DeaOm, mandclu, igork96, VladimirAus: Pattern for the...
vladimiraus’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

leducdubleuet’s picture

Pardon me for asking here on a closed issue but I do not quite understand how this works...

Let's say I have 10 content types with different automatic entity label for the node title for each, how can I translate each one?

If I search for @pattern on /admin/config/regional/translate, I only have one entry there.

Can somebody help me understand the process for translating my 10 patterns please?

Thank you.

ivnish’s picture

Same question

danharper’s picture

Looking for docs on this, It works if you allow title to be translated but that should not be necessary if you're using tokens where the content is already translated?