PHP.mk документација

ngettext

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.ngettext.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.ngettext.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
ngettext

Референца за `function.ngettext.php` со подобрена типографија и навигација.

function.ngettext.php

ngettext

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

ngettext(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

= NULL

ngettext(string $singular, string $plural, int $count): string

Множина верзија на gettext gettext()Множинската верзија на

Параметри

singular

. Некои јазици имаат повеќе од една форма за множински пораки во зависност од бројот.

plural

Единствена порака ID.

count

Множинска порака ID.

Вратени вредности

Бројот (на пр. број на ставки) за да се утврди преводот за соодветниот граматички број. singular and plural Враќа точна множинска форма на пораката идентификувана од count.

Примери

Пример #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

?>

Белешки од корисници 6 белешки

за бројот
пред 17 години
Example for russian lang:
file.po:
    ...
    "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
    ...
    msgid "File"
    msgid_plural "Files"
    msgstr[0] "Файл"
    msgstr[1] "Файла"
    msgstr[2] "Файлов"
    ...

file.php
    ...
    echo ngettext("File", "Files", $number);
    ...
peter at ints dot net
12 години пред
Even though "hek at theeks dot net"'s answer is valid, I would not recommend using the abs() hack recommended. Even though it is by far the most common, not all languages treat (n != 1) as plural. Other languages are much more complex, for example, here is how you determine plurals in Macedonian.

n==1 || n%10==1 ? 0 : 1

In Arabic there are actually 5 different types of plurals:

n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5

If you are using only specific languages that use the (n != 1) format AND -1 is singular, by all means, use abs(), but be careful and don't forget that you have done this when adding a new language to your project 3 years down the road.
Mike Robinson
пред 18 години
It's useful to know how the .po-file has to look like when using ngettext:

msgid "item"
msgid_plural "items"
msgstr[0] "Produkt"
msgstr[1] "Produkte"

In php:

echo ngettext('item', 'items', $number);
kontakt at somplatzki dot de
21 години пред
Section 10.2.5 in the GNU gettext manual explains the ngettext function:

http://www.gnu.org/software/gettext/manual/

(Sorry, but the Add Note function prevents me from including a long URL which points right to that section of the manual.)
mike-php at emerge2 dot com
пред 16 години
Beware of one difference between the GNU gettext API and the PHP binding of it, which is that the GNU gettext functions that accept a $count parameter all expect (indeed, being compiled C, require) that $count be unsigned, while the PHP binding does not.

Thus, the PHP gettext functions will happily accept negative numbers. The one potentially irritating consequence of this is that -1 is treated as plural, which sits well with some people and not so well with others.  (As a picky native speaker of English, my personal opinion is that both "the temperature is minus one degree Fahrenheit" and "four apples minus five apples leaves minus one apple" but others may feel that "four apples minus five apples leaves minus one apples" sounds better.)

The upshot: You may want to abs($count) before passing numbers to gettext.

Bonus points: If your application includes user preferences, you might offer a "treat -1 as singular" option to your users, then choose $count or abs($count) to pass to gettext based on each user's preference.
tokul на users dot sourceforge dot net
19 години пред
According to GNU gettext manual third argument is unsigned long integer. It must be positive number. If n is negative, it might be evaluated incorrectly in some languages.
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.