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.

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

Plural forms format<br />

Since version <strong>1.1</strong>.6 CLDR-based plural choice format can be used with a simpler syntax<br />

that. It is handy for languages with complex plural form rules.<br />

The rule for English plural forms above can be written in the following way:<br />

<strong>Yii</strong>::t('test', 'cucumber|cucumbers', 1);<br />

<strong>Yii</strong>::t('test', 'cucumber|cucumbers', 2);<br />

<strong>Yii</strong>::t('test', 'cucumber|cucumbers', 0);<br />

The code above will give you:<br />

cucumber<br />

cucumbers<br />

cucumbers<br />

If you want to include number you can use the following code.<br />

echo <strong>Yii</strong>::t('test', '{n} cucumber|{n} cucumbers', 1);<br />

Here {n} is a special placeholder holding number passed. It will print 1 cucumber.<br />

You can pass additional parameters:<br />

<strong>Yii</strong>::t('test', '{username} has a cucumber|{username} has {n} cucumbers',<br />

array(5, '{username}' => 'samdark'));<br />

and even replace number parameter with something else:<br />

function convertNumber($number)<br />

{<br />

// convert number to word<br />

return $number;<br />

}<br />

<strong>Yii</strong>::t('test', '{n} cucumber|{n} cucumbers',<br />

array(5, '{n}' => convertNumber(5)));<br />

For Russian it will be:

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

Saved successfully!

Ooh no, something went wrong!