Fix translation of moderation states
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3375490. --> Reported by: [lostcarpark](https://www.drupal.org/user/346773) Related to !40 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>In ScheduledPublishGenericFormatter, the following is used:</p> <div class="codeblock"> <pre><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br>&nbsp; </span><span style="color: #007700">public function </span><span style="color: #0000BB">viewElements</span><span style="color: #007700">(</span><span style="color: #0000BB">FieldItemListInterface $items</span><span style="color: #007700">, </span><span style="color: #0000BB">$langcode</span><span style="color: #007700">): array {<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$elements </span><span style="color: #007700">= [];<br><br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$strDateFormat </span><span style="color: #007700">= </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getSetting</span><span style="color: #007700">(</span><span style="color: #DD0000">'date_format'</span><span style="color: #007700">);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$strTextPattern </span><span style="color: #007700">= </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getSetting</span><span style="color: #007700">(</span><span style="color: #DD0000">'text_pattern'</span><span style="color: #007700">);<br><br>&nbsp;&nbsp;&nbsp; foreach (</span><span style="color: #0000BB">$items </span><span style="color: #007700">as </span><span style="color: #0000BB">$delta </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$item</span><span style="color: #007700">) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #FF8000">/**<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @var \Drupal\scheduled_publish\Plugin\Field\FieldType\ScheduledPublish $item<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$rawValue </span><span style="color: #007700">= </span><span style="color: #0000BB">$item</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$dateTime </span><span style="color: #007700">= </span><span style="color: #0000BB">$rawValue</span><span style="color: #007700">[</span><span style="color: #DD0000">'value'</span><span style="color: #007700">];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$moderationState </span><span style="color: #007700">= </span><span style="color: #0000BB">t</span><span style="color: #007700">(</span><span style="color: #0000BB">$rawValue</span><span style="color: #007700">[</span><span style="color: #DD0000">'moderation_state'</span><span style="color: #007700">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$elements</span><span style="color: #007700">[</span><span style="color: #0000BB">$delta</span><span style="color: #007700">] = [</span><span style="color: #DD0000">'#markup' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">parseData</span><span style="color: #007700">(</span><span style="color: #0000BB">$dateTime</span><span style="color: #007700">, </span><span style="color: #0000BB">$strDateFormat</span><span style="color: #007700">, </span><span style="color: #0000BB">$moderationState</span><span style="color: #007700">, </span><span style="color: #0000BB">$strTextPattern</span><span style="color: #007700">)];<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; return </span><span style="color: #0000BB">$elements</span><span style="color: #007700">;<br>&nbsp; }<br></span><span style="color: #0000BB">?&gt;</span></span></pre></div> <p>This is problematic because is is using UI translation to translate configuration elements. This could lead to site specific translations getting pushed to the drupal.org translations.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Change to use config translation. I think the schema for this is already present in the core workflows module, so it should already be translatable, so it should just be a matter of making sure the correct translated text is used. I expect most translated sites should already have translations in place for their moderation states.</p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <p>Remove t().<br> Check correct translated moderation state is used.<br> Test.<br> Consider adding automated test.<br> Consider providing upgrade script.</p> <h3 id="summary-ui-changes">User interface changes</h3> <p>Translation of the moderation state will be through config translation.</p> <h3 id="summary-api-changes">API changes</h3> <p>None.</p> <h3 id="summary-data-model-changes">Data model changes</h3> <p>None.</p>
issue