L10n

1 Date and Time Formatting

Date and time are often in different formats in different countries or regions.

The task of date and time formatting is thus to generate a date or time string that fits for the specified locale. Yii provides CDateFormatter for this purpose.

Each CDateFormatter instance is associated with a target locale. To get the formatter associated with the target locale of the whole application, we can simply access the dateFormatter property of the application.

The CDateFormatter class mainly provides two methods to format a UNIX timestamp.

  • format : this method formats the given UNIX timestamp into a string according to a customized pattern (e.g. $dateFormatter→format(‘yyyy-MM-dd’,$timestamp)).
  • formatDateTime : this method formats the given UNIX timestamp into a string according to a pattern predefined in the target locale data (e.g. short format of date, long format of time).

2 Number Formatting

Like data and time, numbers may also be formatted differently in different countries or regions. Number formatting includes decimal formatting, currency formatting and percentage formatting. Yii provides CNumberFormatter for these tasks.

To get the number formatter associated with the target locale of the whole application, we can access the numberFormatter property of the application.

The following methods are provided by CNumberFormatter to format an integer or double value.

  • format : this method formats the given number into a string according to a customized pattern (e.g. $numberFormatter→format(‘#,##0.00’,$number)).
  • formatDecimal : this method formats the given number using the decimal pattern predefined in the target locale data.
  • formatCurrency : this method formats the given number and currency code using the currency pattern predefined in the target locale data.
  • formatPercentage : this method formats the given number using the percentage pattern predefined in the target locale data.

3 Localization overriding

By default YII supports many predefined date and times formats. You can find them in /framework/i18n/data

But can happens situation when you need to override some of them. For this purpose Gentics Portal Node have its own folder with localisation settings /common/i18n. In folder common/i18n we have our own l18n files which are inherited from framework i18n files.

There are such rules for this files:

  1. For each locale which we are planning to use in future in Gentics Portal Node we should make own file inside common/i18n. (By default en and de exists)
  2. Yii i18n files are in folder gPortal/framework/i18n/data . Use them to see which options you can override
  3. Each locale file in folder /common/i18n should have name which corresponds to overriding locale
  4. Basic content for OUR locale file is the same:

$coreLocaleFile = Yii::getPathOfAlias('system.i18n.data.' . array_shift(explode('.', basename(FILE)))) . '.php';
return CMap::mergeArray(require $coreLocaleFile, array(
)
);