Class CChoiceFormat
CChoiceFormat is a helper that chooses an appropriate message based on the specified number value. The candidate messages are given as a string in the following format:
'expr1#message1|expr2#message2|expr3#message3'
where each expression should be a valid PHP expression with <span
class="php-quote">'n'</span>
as the only variable. For example,
<span class="php-quote">'n==1'</span>
and
<span class="php-quote">'n%10==2 &&
n>10'</span>
are both valid expressions. The variable
<span class="php-quote">'n'</span>
will take the given
number value, and if an expression evaluates true, the corresponding message
will be returned.
For example, given the candidate messages <span
class="php-quote">'n==1#one|n==2#two|n>2#others'</span>
and
the number value 2, the resulting message will be <span
class="php-quote">'two'</span>
.
For expressions like <span
class="php-quote">'n==1'</span>
, we can also use a shortcut
<span class="php-quote">'1'</span>
. So the above
example candidate messages can be simplified as <span
class="php-quote">'1#one|2#two|n>2#others'</span>
.
In case the given number doesn't select any message, the last candidate message will be returned.
The PHP expressions will be evaluated using CChoiceFormat::evaluate()
.
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Located at x2engine/framework/i18n/CChoiceFormat.php
public static
string
|
|
protected static
boolean
|