ngettext
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
ngettext — Plural version of gettext
Description
The plural version of gettext(). Some languages have more than one form for plural messages dependent on the count.
Parameters
singular
The singular message ID.
plural
The plural message ID.
count
The number (e.g. item count) to determine the translation for the respective grammatical number.
Return Values
Returns correct plural form of message identified by
singular and plural
for count count.
Errors/Exceptions
Throws a ValueError if singular
or plural is longer than 4096 bytes.
Changelog
| Version | Description |
|---|---|
| 8.0.0 |
Now throws a ValueError if an argument
is too long. Previously, an E_WARNING was raised
and false was returned.
|
Examples
Example #1 ngettext() example
<?php
setlocale(LC_ALL, 'cs_CZ');
printf(ngettext("%d window", "%d windows", 1), 1); // 1 okno
printf(ngettext("%d window", "%d windows", 2), 2); // 2 okna
printf(ngettext("%d window", "%d windows", 5), 5); // 5 oken
?>来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
