When exporting the translations from a drupal site with Views, the .po-file contains conflicts due to bad translations.

In includes/admin.inc theme_views_ui_view_info() contain a format plural for translating displays. The code looks like this:

$displays = empty($displays) ? t('None') : format_plural(count($displays), 'Display', 'Displays') . ': ' . '<em>' . implode(', ', $displays) . '</em>'

The problem is that other modules use t() to translate both 'Display' and 'Displays'. This makes very good sence, especially if you look at the description of format_plural: "Formats a string containing a count of items." and "Since t() is called by this function, make sure not to pass already-localized strings to it." The string does first of all not contain a count. Second of all the translation already exists (actually in the same file in the theme_views_ui_reorder_displays_form()!)

I suggest changing the options to the following:

$displays = empty($displays) ? t('None') : (count($displays) == 1 ? t('Display', array(), array('context' => 'noun')) : t('Displays', array(), array('context' => 'noun'))) . ': ' . '<em>' . implode(', ', $displays) . '</em>'

I know it's a bit longer, and not as pretty, but the code is more accurate. The translation doesn't use format_plural, but still checks for 1, and a context is set - it could be the action of displaying (to display/displays) or it could be the noun (one display/two displays).

(I'll try to attach a patch in a comment...)

Comments

lund.mikkel’s picture

Status: Needs work » Needs review
StatusFileSize
new855 bytes

Patch

Edit: had used relative paths to the root of the drupal installation, not the module...

Status: Needs review » Needs work

The last submitted patch, views-display_translation-1729952-1.patch, failed testing.

lund.mikkel’s picture

StatusFileSize
new727 bytes

Patch

lund.mikkel’s picture

dawehner’s picture

Status: Needs review » Needs work
+++ b/includes/admin.incundefined
@@ -819,7 +819,7 @@ function theme_views_ui_view_info($variables) {
+  $displays = empty($displays) ? t('None') : (count($displays) == 1 ? t('Display', array(), array('context' => 'noun')) : t('Displays', array(), array('context' => 'noun'))) . ': ' . '<em>' . implode(', ', $displays) . '</em>';

If you look at the format_plural function you can see that you can add the options there as well, so format_plural($count, $singular, $plural, array(), array('context' => 'noun')); should work as well.

lund.mikkel’s picture

That still doesn't solve the problem with the translations not actually containing the count. We still have the problem that you can't have t('Display') and format_plural($count, 'Display', 'Displays') in the code. format_plural() will cause the .po-file to break. The context is only there to allow better translations with generic words as display...

dawehner’s picture

The reason for adding the $count is to allow people to extend the UI using a different translation, but sure the context is really a valid addition, so why not keep both of them.

ygerasimov’s picture

@lund.mikkel please advise what exactly is broken in .po files when they are generated from views using format_plural() function?

lund.mikkel’s picture

I've extracted the translations from the module, and try to save the file in POEdit without changing anything. I get these errors:

  • At the singular translation of 'Display': "...this is the location of the first definition"
  • At the plural translation of 'Display': "Duplicate message definition"

The second translation even contains the wrong translation of 'Display' being the verb instead of the noun...

lund.mikkel’s picture

Status: Needs work » Needs review
StatusFileSize
new653 bytes

So what is the status here? Just to sum up the problem:

You can't have a translation in a format_plural() that already exists in t(). format_plural() is for translations containing counts (@count) which isn't the case here.

So to use the normal t() we just check if the count is 1. If so, we use the singular translation (Display) otherwise the plural (Displays). This is the correct way to use the translations.

I've created a new patch that doesn't use context, just to make it more clear what the issue is.

drzraf’s picture

adding some more:

$ msgcat views-7.x-3.5.fr.po
views-7.x-3.5.fr.po:3932: duplicate message definition...
views-7.x-3.5.fr.po:186: ...this is the location of the first definition
views-7.x-3.5.fr.po:4282: duplicate message definition...
views-7.x-3.5.fr.po:2911: ...this is the location of the first definition
views-7.x-3.5.fr.po:4286: duplicate message definition...
views-7.x-3.5.fr.po:2915: ...this is the location of the first definition
msgcat: found 3 fatal errors
$ sed -n -e 3932p -e 186p -e 4282p -e 2911p -e 4286p -e 2915p <(nl -ba fr/views-7.x-3.5.fr.po )
   186	msgstr "Affichage"
  2911	msgstr[0] "@count élément, en passer @skip"
  2915	msgstr[0] "@count élément"
  3932	msgid "Display"
  4282	msgid "@count item, skip @skip"
  4286	msgid "@count item"

see also: $ msguniq -d views-7.x-3.5.fr.po

mikran’s picture