Problem/Motivation

The Trash module (3.0.31) wraps CLI/Drush output strings in Symfony Console formatting tags such as <info> and <comment> — but passes them through $this->t(), which makes them translatable strings. Two strings in TrashCliActions::exportViews() are affected:

In TrashCliActions.php, line 109:

$io->writeln((string) $this->t('<info>Exported the @entity_type Trash overview page view.</info>', [
  '@entity_type' => $entity_type->getLabel(),
]));

and in TrashCliActions.php, line 114:

$io->writeln((string) $this->t('<comment>Skipped export of the Trash overview page view for @entity_type because it already exists.</comment>', [
  '@entity_type' => $entity_type->getLabel(),
]));

Because both strings go through $this->t(), they get picked up by the string extraction/localization system and end up in .po translation files. Both are indeed present in trash-3.0.31.de.po, with empty msgstr "" translations:

msgid "<info>Exported the @entity_type Trash overview page view.</info>"
msgstr ""

msgid ""
"<comment>Skipped export of the Trash overview page view for "
"@entity_type because it already exists.</comment>"
msgstr ""

<info> and <comment> are Symfony Console output-formatting tags, not HTML tags — neither is part of Drupal core's allowed tag list checked by locale_string_is_safe() (in core/includes/common.inc). As a result, when a translation is provided for either of these two strings and imported, the import is rejected as unsafe HTML, and the German (or any other language) translation for both strings silently fails to import — they always fall back to the untranslated (and technically malformed, since the console tags leak into any non-CLI rendering) English source string.

Steps to reproduce

  1. Have a site with the Trash module installed and a non-English language configured for translation import.
  2. Run drush trash:export-views --all (or the equivalent core CLI action) so both strings — <info>Exported the @entity_type Trash overview page view.</info> and <comment>Skipped export of the Trash overview page view for @entity_type because it already exists.</comment> — are written to a .po file / picked up by the localization system, with translations provided for them (e.g. via l10n_server / a German .po file such as trash-3.0.31.de.po).
  3. Import that translation, e.g. run drush locale:import or trigger interface translation update on admin/config/regional/translate/import.
  4. Observe that the translations for both strings are rejected/skipped because locale_string_is_safe() does not recognize <info> or <comment> as safe HTML tags.

Proposed resolution

Stop passing Symfony Console formatting tags through $this->t(). These strings are CLI-only output and don't need to (and per Drupal's translation-safety rules, can't cleanly) contain markup tags that aren't valid HTML.

Suggested fix in TrashCliActions::exportViews(): move the <info>/<comment> wrapping outside of the translatable string for both occurrences:

$io->writeln('<info>' . (string) $this->t('Exported the @entity_type Trash overview page view.', [
  '@entity_type' => $entity_type->getLabel(),
]) . '</info>');
$io->writeln('<comment>' . (string) $this->t('Skipped export of the Trash overview page view for @entity_type because it already exists.', [
  '@entity_type' => $entity_type->getLabel(),
]) . '</comment>');

This keeps the console formatting while making the translatable strings themselves plain text, which locale_string_is_safe() will accept, so both translations can be imported correctly.

Remaining tasks

  • Confirm whether other CLI/Drush-facing strings in the module have the same pattern (e.g. check for other $this->t('<...>...</...>') occurrences across the module).
  • Write a patch fixing both strings and add/update tests if applicable.

User interface changes

None (CLI output only).

API changes

None.

Data model changes

None.

Issue fork trash-3615165

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

joachim namyslo created an issue. See original summary.

joachim namyslo’s picture

Title: <info> tag isn't part of string_locale is safe » some strings get skipped whil translationns are imported.
Issue summary: View changes
joachim namyslo’s picture

Title: some strings get skipped whil translationns are imported. » Some strings get skipped while translations are imported
joachim namyslo’s picture

StatusFileSize
new922 bytes

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

  • amateescu committed adb99a66 on 3.1.x
    fix: #3615165 Some strings get skipped while translations are imported...

  • amateescu committed 5a80f4aa on 3.x
    fix: #3615165 Some strings get skipped while translations are imported...

amateescu changed the visibility of the branch 3615165-some-strings-get to hidden.

amateescu’s picture

Version: 3.0.31 » 3.x-dev
Status: Active » Fixed

Fixed on both 3.1.x and 3.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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