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
- Have a site with the Trash module installed and a non-English language configured for translation import.
- 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.pofile / picked up by the localization system, with translations provided for them (e.g. via l10n_server / a German.pofile such astrash-3.0.31.de.po). - Import that translation, e.g. run
drush locale:importor trigger interface translation update onadmin/config/regional/translate/import. - 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | trash-n3543210-info-comment-tags-1.patch | 922 bytes | joachim namyslo |
Issue fork trash-3615165
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:
- 3615165-fix-command-strings
changes, plain diff MR !145
- 3615165-some-strings-get
compare
Comments
Comment #2
joachim namysloComment #3
joachim namysloComment #4
joachim namysloComment #10
amateescu commentedFixed on both 3.1.x and 3.x, thanks!