Weird behaviour of __() function... or not?

Hello.
I’ve been bumping my head for a while on something weird regarding the __() translation function, and I could really use some help.

I’ve added some custom strings to a theme, particularly one to collections/browse page:

<?php 
    echo link_to_items_browse(
        __(plural('Browse %s item in the collection', 'Browse all %s items in the collection', $total), '<b>' . $total . '</b>'),
        array('collection' => metadata('collection', 'id')),
        array('class' => 'view-items-link')
    );
?>

and… the linktext does not get translated.
I’m using the Translations plugin to add custom strings to the theme, and that is working fine because, if I tried to replace the plural() part with any of the two strings, they would get correctly translated. But when passing them both via the plural() function, they remain in English.

I’ve also tried replacing the plural() function with something different:

    echo link_to_items_browse(
        __(($total > 1 ? 'Browse %s item in the collection' : 'Browse all %s items in the collection'), '<b>' . $total . '</b>'),
        array('collection' => metadata('collection', 'id')),
        array('class' => 'view-items-link')
    );
?>

without success, of course.

So, what am I doing wrong? I assumed that according to (https://omeka.readthedocs.io/en/latest/Reference/libraries/globals/plural.html) it should work… Thanks for any advice.

I think the issue is just that plural strings are handled differently in a .po translation file: because different languages have different numbers of plural forms, plurals aren’t just stored as separate single strings in the translation files.

If the Translations plugin doesn’t let you define plural translations, that would probably be the issue here.

Thank you, @jflatnes: you pointed me in the right direction.

The Translations plugin is basically just extending to the current theme’s languages/ directory the chance to add custom .mo language files.

What I was ignoring was that the syntax to be used for plural strings was slightly different. I’ve opened one of the core files, and found the solution (here’s a templace for the benefit of anyone who could incur in the same issue):

msgid "Original string for singular"
msgid_plural "Original string for plural"
msgstr[0] "Translated string for singular"
msgstr[1] "Translated string for plural"

This topic was automatically closed after 250 days. New replies are no longer allowed.