Fix translation of moderation states

Created on 19 July 2023, over 1 year ago
Updated 20 July 2023, over 1 year ago

Problem/Motivation

In ScheduledPublishGenericFormatter, the following is used:

  public function viewElements(FieldItemListInterface $items, $langcode): array {
    $elements = [];

    $strDateFormat = $this->getSetting('date_format');
    $strTextPattern = $this->getSetting('text_pattern');

    foreach ($items as $delta => $item) {
      /**
       * @var \Drupal\scheduled_publish\Plugin\Field\FieldType\ScheduledPublish $item
       */
      $rawValue = $item->getValue();
      $dateTime = $rawValue['value'];
      $moderationState = t($rawValue['moderation_state']);
      $elements[$delta] = ['#markup' => $this->parseData($dateTime, $strDateFormat, $moderationState, $strTextPattern)];
    }

    return $elements;
  }

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.

Proposed resolution

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.

Remaining tasks

Remove t().
Check correct translated moderation state is used.
Test.
Consider adding automated test.
Consider providing upgrade script.

User interface changes

Translation of the moderation state will be through config translation.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇮🇪Ireland lostcarpark

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024