backdrop / backdrop-issues

Issue tracker for Backdrop core.
144 stars 38 forks source link

system_get_debug_info() does not allow translators to provide a correct translation #6515

Open kiamlaluno opened 1 week ago

kiamlaluno commented 1 week ago

system_get_debug_info() uses the following code.

$editor_label .= ' ' . t('version') . ': ' . $editor['library_version'];
$editor_label .= ' ' . t('version') . ': ' . $modules[$editor['module']]->info['version'];

That code has these "issues":

Instead, the output string should be a single string passed to t(), which uses placeholders, similarly to the other string used by the same function.

$debug_info_lines[] = array(
  'label' => $editor,
  'value' => t('Used in formats: @formats', array('@formats' => implode(', ', $formats))),
);

If the version does not really need to be sanitized/escaped, the following code should be used.

$editor_label .= ' ' . t('version: !version', array('!version' => $editor['library_version']));
$editor_label .= ' ' . t('version: !version', array('!version' => $modules[$editor['module']]->info['version']));

Otherwise, a different placeholder needs to be used.

$editor_label .= ' ' . t('version: @version', array('@version' => $editor['library_version']));
$editor_label .= ' ' . t('version: @version', array('@version' => $modules[$editor['module']]->info['version']));
kiamlaluno commented 1 week ago

In French, the translation for version: 3 is version : 3 (with a space before the semicolon). Only when a complete string is passed to t(), translators are able to give a correct translation.

kiamlaluno commented 1 week ago

(I need to avoid editing code when somebody keeps interrupting me.)

kiamlaluno commented 1 week ago

Since $editor['label'] is added to the translated string, I changed the code to the following one.

foreach ($text_formats as $format_info) {
  if (!empty($format_info->editor)) {
    $editor = $text_editors[$format_info->editor];
    if (!empty($editor['library_version'])) {
      $editor_version = $editor['library_version'];
    }
    elseif (isset($modules[$editor['module']]->info['version'])) {
      $editor_version = $modules[$editor['module']]->info['version'];
    }
    $editor_label = t('@editor_label version: @editor_version', array(
      '@editor_label' => $editor['label'],
      '@editor_version' => $editor_version,
    ));
    $text_editor_usage[$editor_label][] = $format_info->name;
  }
}

In this way, translators have a better context, to understand how the text should be translated.