WordPress PHP function _n() only translates singular text

I’m in the process of making our WordPress plugin compatible with translate.wordpress.org and use this code for easy pluralisation/translation:

echo _n( 'size', 'sizes', $count, 'my-domain' );

We still have .po/.mo files that contain e.g.:

Read More
msgid "size"
msgstr "afmeting"

msgid "sizes"
msgstr "afmetingen"

This is the output I get:

echo _n( 'size', 'sizes', 1, 'my-domain' );
// expected: 1 afmeting 
// actual: 1 afmeting 

echo _n( 'size', 'sizes', 2, 'my-domain' );
// expected: 2 afmetingen
// actual: 2 sizes

The translations are there, if I reverse the plural/single texts still only the single is translated.

Any thoughts what I’m doing wrong and how I should get it to work?

Related posts

1 comment

  1. It seems I was not storing plural translations correctly. I’ve modified the plugin code to use translate.wordpress.org and the translation is now regarded as one having both a singular and plural version.

    The solution for storing it in the .po/.mo files would have been something like this (not tested):

    msgid "size"
    msgid_plural "sizes"
    msgstr[0] "afmeting"
    msgstr[1] "afmetingen"
    

    Also see this: Why is msgid_plural necessary in gettext translation files?.

Comments are closed.