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
-
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | workflow-buttons-translated-button.png | 11.25 KB | rossb89 |
| #8 | config-translation-workflow.png | 50.49 KB | rossb89 |
| #2 | use-translation-label--3252754-2.patch | 790 bytes | efpapado |
Issue fork workflow_buttons-3252754
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
efpapado commentedProposing patch.
Comment #3
mlncn commentedThank 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.
Comment #4
efpapado commentedI'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\Transitionobjects, which are not entities.Also in the workflow's schema file
core/modules/workflows/config/schema/workflows.schema.ymlunder theworkflows.transitionschema thelabelhas atranslation context. The translation system is not my strongest point, but this tells me that thet()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 :)
Comment #5
mlncn commentedSuggestion 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?
Comment #8
rossb89 commentedQuestion 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:

Comment #10
mlncn commentedDocumented in README, thanks all!