[wp-polyglots] Do you plural?
Nikolay Bachiyski
nbachiyski at developer.bg
Sat Dec 30 14:40:10 GMT 2006
Hello, dear translators, i18n-ers and l10n-ers, and other interested ones,
We are fortunate enough to live in a plural and not in a singular
world (except for the women, at least for myself ;) ), so it will be
shame not to turn this quality to our beloved WordPress.
Once the Dashboard of my test blog said:
There are currently 25 posts and 1 comments, contained within 5 categories.
Now it says:
There are currently 25 posts and 1 comment, contained within 5 categories.
Shall I emphasise the *comment* vs. *comment*? I guess not.
Fortunately gettext has quite nice support for plural forms and now on
it shall be used and here are some clues to using it:
1. Localization.
This section contains instructions for WordPress translators.
First you will have to define the linguistic characteristics of plural
forms in your language in the PO file.
Most translating programs allow you to specify two values: nplurals
and plural. nplurals show how many plural forms are there in your
language. plurals is a string, describing which plural form should be
used depending on the number of items. Here are some examples:
English - nplurals=2; plural=n != 1
In English (and many other languages) there is a singular form used
when there is only one item and on every other occasion the plural
form is used.
Irish - nplurals=3; plural=n==1 ? 0 : n==2 ? 1 : 2
The criptic expression for plural could be translated to: If the
quantity is 1 - use the first plural form (indexing starts from 0), if
the number of items is 2 - use the second plural form, else use plural
form number 2 (or the third one, actually).
For more explanations and examples, refer to [1] once again.
Then comes the translating, which is easy with the modern translating
software :-) If you still edit your po files by hand I suppose you are
hacker enough to read the needed documentation and cope with it
yourself. In case of any problems - write to the list - we will try to
help :)
2. Internationalization
This section is aimed at developers, who would like to contribute code
to WordPress or write a plugin and also would like to internationalize
plural forms of messages.
Let's for example, try to internationalize the text:
%s comments
We could something like that:
if (1 == $approved) {
_e('1 comment approved');
} else {
printf(__('%s comments approved'), $approved);
}
However this scheme has proved unsuccessful due to the specifics of
many languages, which do not have only two plural forms (for a real
example - see [1]). As a consequence, the ngettext function was born
(in our case - __ngettext). The snippet above could be legally
transformed to:
printf(__ngettext('%s comment approved', '%s comments approved',
$approved), $approved);
The __ngettext function accepts four parameters:
function __ngettext($singular, $plural, $number, $domain='default')
$singular: the singular form of the message in English
$plural: the plural form of the message in English
$number: the actual number of items
The __ngettext function just returns the appropriate translation of
the string, given the supplied quantity. If there isn't any
corresponding translation - it returns the singular form if the
quantity is 1 and the plural form otherwise.
The new pot file already includes the plural messages, so go for it! :-)
Happy translating,
Nikolay
[0] http://trac.wordpress.org/changeset/4658
[1] http://www.gnu.org/software/gettext/manual/html_chapter/gettext_10.html#SEC150
More information about the wp-polyglots
mailing list