Problem/Motivation

The buttons generated by this widget use the transition label without translating it.

Steps to reproduce

  • Add a second language to the site
  • Translate the transitions to the new language
  • Load the entity form on the new language
  • Problem: The button gets the transition label's original language, instead of the translated one.

Proposed resolution

Upcoming patch.

Remaining tasks

-

User interface changes

The buttons will show the translated label instead of the original.

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

efpapado created an issue. See original summary.

efpapado’s picture

Status: Active » Needs review
StatusFileSize
new790 bytes

Proposing patch.

mlncn’s picture

Thank you!

Putting a variable inside of t() is not the correct way of using t() though, right? Or am i behind the times?

Definitely want this translatable and willing to bring this in as a workaround if needed, but if there's some more correct way of doing this i would like to make a follow-up issue.

efpapado’s picture

I'm also not sure if there's indeed a better way. The $this->validator->getValidTransitions($entity, $this->currentUser) a few lines above returns an array of \Drupal\workflows\Transition objects, which are not entities.
Also in the workflow's schema file core/modules/workflows/config/schema/workflows.schema.yml under the workflows.transition schema the label has a translation context. The translation system is not my strongest point, but this tells me that the t() is supposed to be used after retrieving the label value.
I think it is safe to just throw the variable in the t() directly since we have validated already that it will be a transition label.
Maybe a better practice would be to extend the t() function into the widget's class?

Maybe someone more familiar with the translation system can have a say :)

mlncn’s picture

Suggestion in slack contrib channel (from Sam Becker) is to use config translation module in core.

Question 1: Does enabling that allow workflow transitions to be translated?

Question 2: Do we have to do anything to load the correct translation of these config-stored transition names?

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

rossb89’s picture

Status: Needs review » Needs work
StatusFileSize
new50.49 KB
new11.25 KB

Question 1: Does enabling that allow workflow transitions to be translated?
Yes, you can find and translate your workflow(s) here: e.g. /admin/config/regional/config-translation/workflow.
By clicking translate there, you can translate all states and transitions for that workflow for any language you have enabled on your site.

Question 2: Do we have to do anything to load the correct translation of these config-stored transition names?
No. I just tested this out by saving a translation for e.g. a 'Publish' workflow transition for a non english language and it was displayed correctly as the button label.

TLDR:
This all just works (as of 8.7.x #3037906) and you just need to use the config translation system as you would for other things, no changes need to take place for this workflow_buttons module.

I'm just wondering if this needs to be made clearer in the module readme perhaps, if people haven't worked out how to translate the labels? Marking as needs work in case we think that is worth while... or lets just close this as works as designed.

Translating the config:

Viewing the translated button:

  • mlncn committed b3db2edb on 8.x-1.x authored by rossb89
    Issue #3252754 by mahtab_alam, efpapado, rossb89, mlncn: Document how to...
mlncn’s picture

Status: Needs work » Fixed

Documented in README, thanks all!

Status: Fixed » Closed (fixed)

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