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...)
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | views-display_translation-1729952-10.patch | 653 bytes | lund.mikkel |
| #9 | Skærmbillede 2012-08-19 kl. 09.58.07.png | 139.97 KB | lund.mikkel |
| #9 | Skærmbillede 2012-08-19 kl. 09.58.29.png | 52.49 KB | lund.mikkel |
| #9 | Skærmbillede 2012-08-19 kl. 09.58.44.png | 123.18 KB | lund.mikkel |
| #1 | views-display_translation-1729952-1.patch | 855 bytes | lund.mikkel |
Comments
Comment #1
lund.mikkel commentedPatch
Edit: had used relative paths to the root of the drupal installation, not the module...
Comment #3
lund.mikkel commentedPatch
Comment #4
lund.mikkel commentedComment #5
dawehnerIf 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.
Comment #6
lund.mikkel commentedThat 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')andformat_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...Comment #7
dawehnerThe 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.
Comment #8
ygerasimov commented@lund.mikkel please advise what exactly is broken in .po files when they are generated from views using format_plural() function?
Comment #9
lund.mikkel commentedI've extracted the translations from the module, and try to save the file in POEdit without changing anything. I get these errors:
The second translation even contains the wrong translation of 'Display' being the verb instead of the noun...
Comment #10
lund.mikkel commentedSo what is the status here? Just to sum up the problem:
You can't have a translation in a
format_plural()that already exists int().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.
Comment #11
drzraf commentedadding some more:
see also:
$ msguniq -d views-7.x-3.5.fr.poComment #12
mikran commented