Action Error: Unrecognized locale "".

Hi Guys,

Im getting this continually in my application.log file. I can figure out that the locales not being set but im not sure how to set it manually? I have in my main config file


'language'=>'en',

but that doesnt seem to be making any difference. The method its firing from isnt doing anything fancy




public function afterFind($event){

	foreach($event->sender->tableSchema->columns as $columnName => $column){

		

		if ($this->handleColumn($event, $columnName, $column))

			if ($column->dbType == 'date')

				$event->sender->$columnName = Yii::app()->dateFormatter->format('dd-MM-yyyy', $event->sender->$columnName );

			else

				$event->sender->$columnName = strtotime( $event->sender->$columnName );

	}

	return true;

}




Any ideas?

Thanks!

Ross

2012/03/08 12:38:08 [error] [application] Action Error: Unrecognized locale "".

2012/03/08 12:38:21 [error] [exception.CException] exception ‘CException’ with message ‘Unrecognized locale “”.’ in /home/ninety7/yii-1.1.10.r3566/framework/i18n/CLocale.php:105

Stack trace:

#0 /home/ninety7/yii-1.1.10.r3566/framework/i18n/CLocale.php(65): CLocale->__construct(false)

#1 /home/ninety7/yii-1.1.10.r3566/framework/base/CApplication.php(383): CLocale::getInstance(false)

#2 /home/ninety7/yii-1.1.10.r3566/framework/base/CApplication.php(422): CApplication->getLocale()

#3 /home/ninety7/yii-1.1.10.r3566/framework/base/CComponent.php(112): CApplication->getDateFormatter()

#4 /home/ninety7/yii-1.1.10.r3566/framework/base/CModule.php(106): CComponent->__get(‘dateFormatter’)

#5 /home/ninety7/testApp/protected/extensions/DateTimeBehavior.php(19): CModule->__get(‘dateFormatter’)

#6 /home/ninety7/yii-1.1.10.r3566/framework/base/CComponent.php(559): DateTimeBehavior->afterFind(Object(CEvent))

#7 /home/ninety7/yii-1.1.10.r3566/framework/db/ar/CActiveRecord.php(872): CComponent->raiseEvent(‘onAfterFind’, Object(CEvent))

#8 /home/ninety7/yii-1.1.10.r3566/framework/db/ar/CActiveRecord.php(971): CActiveRecord->onAfterFind(Object(CEvent))

#9 /home/ninety7/yii-1.1.10.r3566/framework/db/ar/CActiveRecord.php(1799): CActiveRecord->afterFind()

#10 /home/ninety7/yii-1.1.10.r3566/framework/db/ar/CActiveRecord.php(1287): CActiveRecord->populateRecord(Array)

#11 /home/ninety7/yii-1.1.10.r3566/framework/db/ar/CActiveRecord.php(1422): CActiveRecord->query(Object(CDbCriteria))

#12 /home/ninety7/testApp/protected/modules/club/controllers/ClubMembersController.php(19): CActiveRecord->findByPk(‘124’)

#13 [internal function]: ClubMembersController->actionView(‘124’)

#14 /home/ninety7/yii-1.1.10.r3566/framework/web/actions/CAction.php(107): ReflectionMethod->invokeArgs(Object(ClubMembersController), Array)

#15 /home/ninety7/yii-1.1.10.r3566/framework/web/actions/CInlineAction.php(48): CAction->runWithParamsInternal(Object(ClubMembersController), Object(ReflectionMethod), Array)

#16 /home/ninety7/yii-1.1.10.r3566/framework/web/CController.php(309): CInlineAction->runWithParams(Array)

#17 /home/ninety7/yii-1.1.10.r3566/framework/web/CController.php(287): CController->runAction(Object(CInlineAction))

#18 /home/ninety7/yii-1.1.10.r3566/framework/web/CController.php(266): CController->runActionWithFilters(Object(CInlineAction), Array)

#19 /home/ninety7/yii-1.1.10.r3566/framework/web/CWebApplication.php(276): CController->run(‘view’)

#20 /home/ninety7/yii-1.1.10.r3566/framework/web/CWebApplication.php(135): CWebApplication->runController(‘club/clubMember…’)

#21 /home/ninety7/yii-1.1.10.r3566/framework/base/CApplication.php(162): CWebApplication->processRequest()

#22 /home/ninety7/public_html/index.php(16): CApplication->run()

#23 {main}

try to add

‘sourceLanguage’ => ‘en’,

to your config

Hi Sanchez,

Thanks for the suggestion. Tried it but still getting the error. Its filling the logs pretty quickly. Anyone any other ideas?

Thanks

Ross

Anyone any ideas on this? Still filling up my logs at a hell of a rate. Worried about disk space issues etc.

I’m also getting this error I notice when sites attempt to use cURL or a non-browser process to talk to my Yii site. For example, when Facebook attempts to verify my site it apparently uses some sort of script and not a “real browser” of course.

So what’s happening is is that the language code normally sent by a browser appears to be missing and Yii isn’t handling this. I can do a test and manually set the Accept-Language flag in the HTTP header and the site displays, but if I don’t do this, I get the Unrecognized Locale and it errors out.

The only fix I could find was to change the core (gasp) and edit framework/web/CHttpRequest.php and in the getPreferredLanguages() function change

$sortedLanguages=array();

to

$sortedLanguages=array(‘en’);

So this fixed my problem with cURL. But of course, I didn’t want to change anything in the core since that could cause problems, but I can’t find any other way to make Yii use a default language. (Yes, all the obvious stuff such as main.php ‘language’ => ‘en’ and ‘sourceLanguage’ => ‘en’ are set, and the site works just fine through any regular browser – just not a script call like cURL).

I had a similar error:

Unrecognized locale "et_EE"

It appeared that a language file was not found (or named as expected).

To learn what lang file it’s looking for, I just modified the core file framework/i18n/CLocale.php line (104 in my version)

throw new CException(Yii::t(‘yii’,‘Unrecognized locale “{locale}”. The file Im looking for: ‘.$dataFile,array(’{locale}’=>$id)));

now the exception gives the needed information and the missing file was et_ee.php

Problem solved.

I solved this problem by creating my own components/Controller.php and adding the following code into it:




<?php

class Controller extends CController {


    public function init(){ 

        parent::init();


        //set user language

        $app = Yii::app();        

        if (isset($_REQUEST['_lang'])) { //set this in one of your http requests, e.g. as a result of clicking on a language selector

            $app->session['_lang'] = $_REQUEST['_lang'];

        } else { //take language from browser's settings           

            if (!isset($app->session['_lang'])) $app->session['_lang'] = substr($app->getRequest()->getPreferredLanguage(),0,2); // 'fr_FR' becomes 'fr'

        }           

        if (!empty($app->session['_lang'])) {

            $app->language = $app->session['_lang'];

        } 

        if (empty($app->language)) $app->language = "en"; //default language

    }


}



Of course, I need to make sure all my controllers inherit from this class.