The locale mess around

I’m a bit confused when it comes to Yii and i18n and l10n.

In the config/main.php I only can define a default language, but no country.


locale_id = lowercase(language + "_" + country);

But Yii mixes up languages and locales. Why? A language id is no locale id.

My case: A simple drop down with countries: "de", "at" and "ch".

The user chooses his country: “ch”. Ok. What’s next?

Shall I use Yii::app()->language="de_ch" ?

The Yii-core translation files are only available under the locale_id "de", so now every error message appears in english, instead of german. But as Switzerland has (partly) the same language, but other currency as germany I DO have to choose this way.

If I save the country separately in a session (or whatever) and it’ll look like this:




$country = Yii::app()->session['country'];

$language = Yii::app()->language;



… but the currency problem isn’t solved.

Very messy I think.

I’d suggest the following:

  • A user can set a locale, or a language and/or a country

  • If user sets a country and no language is defined or the actual language isn’t spoken in this country, use the default language of the selected country.

  • If user sets a language and there’s no country defined, or the language isn’t spoken in the actual country use a default country for this language.

  • User gets/sets the language by Yii::app()->language, the country by Yii::app()->country and the locale by Yii::app()->locale

  • Like in Zend: If there’s no country specific language file, use the default language file if(!file_exists(“de_at”)) use “de”

Would this be possible?

How can I set locale?

In a view I put


CVarDumper::dump(Yii::app()->locale);

Outputs


   CLocale#1

(

    [CLocale:_id] => 'en_us'

    [CLocale:_data] => array

    (

        'version' => '4123'

        'numberSymbols' => array

        (

            'decimal' => '.'

            'group' => ','

            'list' => ';'

            'percentSign' => '%'

<!-- and so on -->



where is this set??

doodle

Set locale in config/main.php


return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'Tatamagouche Centre',

        'sourceLanguage'=>'en_CA',

        

	// preloading 'log' component

valid locales are in framework/i18n/data stored as individual .php files

*Note:if using faceplugs extension your locale may cause an error because facebook does not support all countries (but they do have pirate and klingon :blink: ) English speaking canada is not supported by facebook (apparently we are Americans). It’s easy enough to add your own in the extension.

doodle