20.11.2014 Views

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Tip: The yiic tool in <strong>Yii</strong> can be used to manage message translations when<br />

CPhpMessageSource is used as the message source. Its message command can<br />

automatically extract messages to be translated from selected source files and merge<br />

them with existing translations if necessary. For more details of using the message<br />

command, please run yiic help message.<br />

Starting from version 1.0.10, when using CPhpMessageSource to manage message<br />

source, messages for an extension class (e.g. a widget, a module) can be specially<br />

managed and used. In particular, if a message belongs to an extension whose class name<br />

is Xyz, then the message category can be specified in the format of Xyz.categoryName.<br />

The corresponding message file will be assumed to beBasePath/messages/LanguageID/<br />

categoryName.php, where BasePath refers to the directory that contains the extension<br />

class file. And when using <strong>Yii</strong>::t() to translate an extension message, the following format<br />

should be used, instead:<br />

<strong>Yii</strong>::t('Xyz.categoryName', 'message to be translated')<br />

Since version 1.0.2, <strong>Yii</strong> has added the support for choice format. Choice format refers to<br />

choosing a translated according to a given number value. For example, in English the<br />

word 'book' may either take a singular form or a plural form depending on the number of<br />

books, while in other languages, the word may not have different form (such as Chinese)<br />

or may have more complex plural form rules (such as Russian). Choice format solves this<br />

problem in a simple yet effective way.<br />

To use choice format, a translated message must consist of a sequence of expressionmessage<br />

pairs separated by |, as shown below<br />

'expr1#message1|expr2#message2|expr3#message3'<br />

where exprN refers to a valid PHP expression which evaluates to a boolean value<br />

indicating whether the corresponding message should be returned. Only the message<br />

corresponding to the first expression that evaluates to true will be returned. An expression<br />

can contain a special variable named n (note, it is not $n) which will take the number value<br />

passed as the first message parameter. For example, assuming a translated message is:<br />

'n==1#one book|n>1#many books'<br />

and we are passing a number value 2 in the message parameter array when calling <strong>Yii</strong>::t(),<br />

we would obtain many books as the final translated message:<br />

<strong>Yii</strong>::t('app', 'n==1#one book|n>1#many books', array(1)));<br />

//or since <strong>1.1</strong>.6<br />

<strong>Yii</strong>::t('app', 'n==1#one book|n>1#many books', 1));<br />

As a shortcut notation, if an expression is a number, it will be treated as n==Number.<br />

Therefore, the above translated message can be also be written as:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!