Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Gettext
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Plural form == The <code>ngettext()</code> interface accounts for the count of a noun in the string. As with the convention of <code>gettext()</code>, it is often aliased to <code>N_</code> in practical use. Consider the code sample: <syntaxhighlight lang="C"> // parameters: english singular, english plural, integer count printf(ngettext("%d translated message", "%d translated messages", n), n); </syntaxhighlight> A header in the <code>""</code> (empty string) entry of the PO file stores some metadata, one of which is the plural form that the language uses, usually specified using a C-style [[?:|ternary operator]]. Suppose we want to translate for the [[Slovene language]]: <syntaxhighlight lang="po"> msgid "" msgstr "" "..." "Language: sl\n" "Plural-Forms: nplurals=4; plural=(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0);\n" </syntaxhighlight> Since now there are four plural forms, the final po would look like:<!-- example from gettext-tools/po/sl.po --> <syntaxhighlight lang="po"> #: src/msgfmt.c:876 #, c-format msgid "%d translated message" msgid_plural "%d translated messages" msgstr[0] "%d prevedenih sporočil" msgstr[1] "%d prevedeno sporočilo" msgstr[2] "%d prevedeni sporočili" msgstr[3] "%d prevedena sporočila" </syntaxhighlight> Reference plural rules for languages are provided by the [[Unicode consortium]].<ref>{{cite web |title=Language Plural Rules |url=https://unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html |website=unicode.org}}</ref> msginit also prefills the appropriate rule when creating a file for one specific language.<ref name=msginit/>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)