Problem With Localedatapath Between Cwebapplication And Cconsoleapplication

Hi.

I’ve an app for which I share config between web and console app. I also have some custom localization formats in protected/i18n/data/.

In my config/main.php I have:


  return array(

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

      'name'=>'My Web Application',

      'sourceLanguage'=>'it',

      'language'=>'it',

      'theme'=>'shadow_dancer',

      'timeZone'=>'Europe/Rome',

      'localeDataPath'=>'protected/i18n/data',

      'behaviors' => array('ApplicationConfigBehavior'),



then my config/console.php has the following content:


$mainConfigArray = include dirname(__FILE__).DIRECTORY_SEPARATOR.'main.php';


// This is the configuration for yiic console application.

// Any writable CConsoleApplication properties can be configured here.

return array(

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

    'name'=>'My Web App CLI',

    'language'=>$mainConfigArray['language'],

    'sourceLanguage'=>$mainConfigArray['sourceLanguage'],

    'timeZone'=>$mainConfigArray['timeZone'],

    'localeDataPath'=>$mainConfigArray['localeDataPath'],



Everything works great in Web, but with this config when I run a console command I get an error “Unknown localization ‘it’”.

If I change localeDataPath to “dirname(FILE).DIRECTORY_SEPARATOR.’…’.DIRECTORY_SEPARATOR.‘i18n/data’” then the localization file is loaded correctly but I get another error saying $GLOBALS[‘yii’] is not defined.

In my locale file I have


return CMap::mergeArray(

    require(dirname($GLOBALS['yii']).'/i18n/data/'.basename(__FILE__)),

    array(

        'dateFormats' => array(

            'full' => 'EEEE d MMMM Y',

            'long' => 'dd MMMM yyyy',

            'medium' => 'dd/MM/yyyy',

            'short' => 'dd/mm/yy',

            'database'=>Yii::app()->params['database_format']['date'],

        ),  

    )   

);



What’s wrong?

thanks

changing in config/main.php


'localeDataPath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'i18n/data',

and in my i18n/data/it.php


require(Yii::getPathOfAlias('system.i18n.data').DIRECTORY_SEPARATOR.basename(__FILE__)),

works for both web and console