Wordpress PHP function _n () only translates special text

I'm in the process of creating our Wordpress plugin compatible with translate.wordpress.org and use this code for easy pluralization / translation:

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

We still have .po / .mo files that contain, for example:

 msgid "size" msgstr "afmeting" msgid "sizes" msgstr "afmetingen" 

This is the result 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 

Translations are, if I cancel multiple / single texts, there is only one translation left.

Any thoughts on what I'm doing wrong, and how should I make it work?

+5
source share
1 answer

It seems that I did not store multiple translations correctly. I changed the plugin code to use translate.wordpress.org, and now the translation is considered as a single and multiple version.

A solution for storing it in .po / .mo files would be 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? .

+2
source

Source: https://habr.com/ru/post/1240544/


All Articles