Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
9332a895
Commit
9332a895
authored
Dec 01, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated docs about plural rules
fixes #6321
parent
30505659
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
14 deletions
+15
-14
tutorial-i18n.md
docs/guide/tutorial-i18n.md
+15
-14
No files found.
docs/guide/tutorial-i18n.md
View file @
9332a895
...
...
@@ -233,32 +233,33 @@ Will produce "You are here for 47 sec. already!".
#### Plurals
Different languages have different ways to inflect plurals.
Some rules are very complex so it's very handy that this
functionality is provided without the need to specify inflection rule. Instead it only requires your input of inflected
words in certain situations
.
Different languages have different ways to inflect plurals.
Yii provides a convenient way for translating messages in
different plural forms that works well even for very complex rules. Instead of dealing with the inflection rules directly
it is sufficient to provide the translation of inflected words in certain situations only
.
```
php
echo
\Yii
::
t
(
'app'
,
'There {n, plural, =0{are no cats} =1{is one cat} other{are # cats}}!'
,
[
'n'
=>
0
]);
echo
\Yii
::
t
(
'app'
,
'There {n, plural, =0{are no cats} =1{is one cat} other{are # cats}}!'
,
[
'n'
=>
$n
]);
```
Will give us
"There are no cats!".
Will give us
In the plural rule arguments above
`=0`
means exactly zero,
`=1`
stands for exactly one
`other`
is for any other number.
`#`
is replaced with the
`n`
argument value. It's not that simple for languages other than English. Here's an example
-
"There are no cats!" for
`$n = 0`
,
-
"There is one cat!" for
`$n = 1`
,
-
and "There are 42 cats!" for
`$n = 42`
.
In the plural rule arguments above
`=0`
means exactly zero,
`=1`
stands for exactly one, and
`other`
is for any other number.
`#`
is replaced with the value of
`n`
. It's not that simple for languages other than English. Here's an example
for Russian:
```
Здесь {n, plural, =0{котов нет} =1{есть один кот} one{# кот} few{# кота} many{# котов} other{# кота}}!
```
In the above it worth mentioning that
`=1`
matches exactly
`n = 1`
while
`one`
matches
`21`
or
`101`
.
Note that if you are using a placeholder twice and one time it's used as
`plural`
another one should be used as
`number`
else
you'll get "Inconsistent types declared for an argument: U_ARGUMENT_TYPE_MISMATCH" error:
In the above it's worth mentioning that
`=1`
matches exactly
`n = 1`
while
`one`
matches
`21`
or
`101`
.
```
Total {count, number} {count, plural, one{item} other{items}}.
```
Note, that you can not use the Russian example in
`Yii::t()`
directly, you have to adjust the
[
[yii\base\Application::$sourceLanguage|source language
]
] setting in your application config
so that Yii knows which language you are using to apply the correct plural rules.
To learn which inflection forms you should specify for your language you can referrer to the
[
rules reference at unicode.org
](
http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
)
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment