Simple Question to I18N

hi there,

yii has a great i18n feature. and for me its no problem to make languages like "en" oder "en_us" etc. in the config file. but i see a limitation. this is not only yii specific its more pattern problem.

e.g. how can i solve the problem, when i have a website in the german language but i want the specific settings of US (currency should be Dollar, dateformat, decimal etc.), so like de_us?

so my question why the country specific settings are a part of the language? and i search of pattern which solve this problem.

i thanks for feedbacks

regards

cihan

I would set the Language to en and a translation file which translates to german instead to english

Other solutions:

1. Create your own instances of CNumberFormatter and CDateFormatter and use them instead of Yii::app()->numberFormatter, Yii::app()->dateFormatter.

2. Extend CApplication, or more possible CWebApplication since that’s the one you will instantiate in your start script.




public function getLocale($localeID=null)

{

  return CLocale::getInstance($localeID===null?$this->getLanguage():$localeID);

}

...

public function getNumberFormatter()

{

  return $this->getLocale()->getNumberFormatter();

}

...

public function getDateFormatter()

{

  return $this->getLocale()->getDateFormatter();

}



As you can see every access to the builtin formatters will use the language property (only one singleton instance per locale will be generated). So you should be able to override getLocale() with some code of your choice.

Note that there is a third dependence in the method Yii::t() resident in YiiBase.php. This statement is used to select plural rules located in the CLocale instance corresponding to the selected language.




$expressions=self::$_app->getLocale($language)->getPluralRules();



Another remaining problem will be that the locale you want to use isn’t available from framework core. Have a look at setLocaleDataPath().

Hopefully Yii 2.0 will offer an option to specify I18N and L10N separately in rare less frequent cases like this.

(untested)

/Tommy