140 likes | 366 Views
Yii Framework i18n – Internationalisation. Cass Surek cass@surek.co.uk. Motivation. Expand product reach Cater for multiple markets Improve usability. i 18n - Internationalisation. Software design process Multiple targets Multiple languages Multiple regions Avoid structural changes
E N D
Yii Frameworki18n – Internationalisation Cass Surek cass@surek.co.uk
Motivation • Expand product reach • Cater for multiple markets • Improve usability
i18n - Internationalisation • Software design process • Multiple targets • Multiple languages • Multiple regions • Avoid structural changes • i + 18 letters + n – coined by DEC in the ’70s
L10n - Localisation • Software adaptation process • Based on internationalised software • Use of locales • Term translation
Yii support for i18n + L10n • Locale and language • Translation • Date and Time Formatting • Number Formatting
Locale • CLocale class– e.g. Yii::app()->locale->dateFormat • Locale codes: en_us, pt_br, en_gb, es (standardised lowercase) • Provides locale specific parameters • Date format • Currency symbols • Month names • Etc
Language • Active locale setup on config file or at runtime • Alters error messages to target language Target Language 1 (pt_br) Source Language (en_us) Target Language 2 (es) Target Language 3 (fr_fr)
Activation - setup • Config file • /protected/config/main.php • Array(‘sourceLanguage’=>’en_gb’, ‘language’=>’pt_br’) • Runtime • Yii::app()->language= ‘pt_br’;
Translation • Messages • Views
Translation - Messages Storage formats • CPhpMessageSource (protected/messages) • CGettextMessageSource (GNU Gettextfiles) • CDbMessageSource (term tables) • Yii::t(’category', 'Path alias "{alias}" is redefined.’, array('{alias}'=>$alias))
Translation - Views • CApplication::findLocalizedFile() – returns language view file name if exists • protected/views/ControllerID/zh_cn/edit.php • Also used for images and data files
Date and Time Formatting • CDateFormatterclass • Yii::app()->dateFormatter • Uses current locale format • Example • Yii::app()->dateFormatter->formatDateTime(time())
Number Formatting • CNumberFormatterclass • Yii::app()->numberFormatter • Uses current locale format • Example • Yii::app()->numberFormatter->formatDecimal("8495873.00")