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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

canonicalized to the format of LanguageID or LanguageID_RegionID in lower case (e.g.<br />

en, en_us).<br />

Locale data is represented as a CLocale instance. It provides locale-dependent<br />

information, including currency symbols, number symbols, currency formats, number<br />

formats, date and time formats, and date-related names. Since the language information is<br />

already implied in the locale ID, it is not provided by CLocale. For the same reason, we<br />

often interchangeably using the term locale and language.<br />

Given a locale ID, one can get the corresponding CLocale instance by<br />

CLocale::getInstance($localeID) or CApplication::getLocale($localeID).<br />

Info: <strong>Yii</strong> comes with locale data for nearly every language and region. The data is<br />

obtained from Common Locale Data Repository (CLDR). For each locale, only a<br />

subset of the CLDR data is provided as the original data contains a lot of rarely used<br />

information. Starting from version <strong>1.1</strong>.0, users can also supply their own customized<br />

locale data. To <strong>do</strong> so, configure the CApplication::localeDataPath property with the<br />

directory that contains the customized locale data. Please refer to the locale data files<br />

under framework/i18n/data in order to create customized locale data files.<br />

For a <strong>Yii</strong> application, we differentiate its target language from source language. The target<br />

language is the language (locale) of the users that the application is targeted at, while the<br />

source language refers to the language (locale) that the application source files are written<br />

in. Internationalization occurs only when the two languages are different.<br />

One can configure target language in the application configuration, or change it<br />

dynamically before any internationalization occurs.<br />

Tip: Sometimes, we may want to set the target language as the language preferred by<br />

a user (specified in user's browser preference). To <strong>do</strong> so, we can retrieve the user<br />

preferred language ID using CHttpRequest::preferredLanguage.<br />

Translation<br />

The most needed I18N feature is perhaps translation, including message translation and<br />

view translation. The former translates a text message to the desired language, while the<br />

latter translates a whole file to the desired language.<br />

A translation request consists of the object to be translated, the source language that the<br />

object is in, and the target language that the object needs to be translated to. In <strong>Yii</strong>, the<br />

source language is default to the application source language while the target language is<br />

default to the application language. If the source and target languages are the same,<br />

translation will not occur.<br />

Message Translation<br />

Message translation is <strong>do</strong>ne by calling <strong>Yii</strong>::t(). The method translates the given message<br />

from source language to target language.

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

Saved successfully!

Ooh no, something went wrong!