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 Overwriting localization

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

In some situations you need to overwrite some of them. For this purpose Gentics Portal Node has a separate folder for custom localisation settings /common/i18n. In the folder common/i18n there are i18n files which are inherited from the framework i18n files.

There are such rules for this files:

  1. For each locale which we are planning to use in the future in Gentics Portal Node we should make our own file inside common/i18n (by default en and de exists).
  2. Framework i18n files are in the folder <portal>/framework/i18n/data . Use them to see which options you can overwrite
  3. Each locale file in folder /common/i18n should have a name which corresponds to overwritten 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(

	)
);