I have read this topic www.yiiframework.com/wiki/208 /how-to-use-an-application-behavior-to-maintain-runtime-configuration/ to use i18N in a single application I have built.
After include in config/main.php (as that post suggest):
As you can imagine I was wrong, I found out that the right place to put the snipped code “‘behaviors’ => array(‘ApplicationConfigBehavior’),” must be inside ‘components’=>array( … )
instead into the top return array( … )
of (../protected/config/main.php) file.
Captcha works fine now.
Thanks for your help.
But second issue ( www.yiiframework.com/wiki/208 /how-to-use-an-application-behavior-to-maintain-runtime-configuration/) I could not figure out, even I’ve read comment #5842 and #5061.
I change dropbox options among the languages (such as from ‘en’ to ‘pt_br’) and nothing happens.
I just set up ../messages/pt_br folder and the array translation file (I called it translation.php).
Do I need set up at the top of file ../protected/config/main.php?
// language i18N
‘sourceLanguage’=>‘en’,
‘language’=>‘pt_br’,
When I do that (lines above) I can see translated messages, also the drop box appears and I’m able to change its options, but whenever I do that, I see nothing translates.
1- My component controller is called ApplicationConfigBehavior and I’ve putted it in ../protected/components/ApplicationConfigBehavior.php
[font="Courier New"]<?php
class ApplicationConfigBehavior extends CBehavior
{
3391
public function init() {
Yii::app()->language = 'pt_br';
}
public function events()
{
return array_merge(parent::events(), array(
'onBeginRequest'=>'beginRequest',
));
}
public function beginRequest()
{
if (isset($_POST['_lang']))
$this->owner->user->setState('applicationLanguage', $_POST['_lang']);
if ($this->owner->user->getState('applicationLanguage'))
$this->owner->language=$this->owner->user->getState('applicationLanguage');
else
$this->owner->language='en';
}
}[/font]
2- My widget is called LangBox and I’ve putted it in ../protected/components/LangBox.php
[font="Courier New"]<?php
class LangBox extends CWidget
{
public function run()
{
$currentLang = Yii::app()->language;
$this->render('langBox', array('currentLang' => $currentLang));
}
}
?>[/font]
3- My form is called langBox and I’ve putted it in ../protected/components/views/langBox.php
[font="Courier New"]<?php echo CHtml::form(); ?>
<div id="langdrop">
<?php echo CHtml::dropDownList('_lang', $currentLang, array(
'en_us' => 'English', 'pt_br' => 'Brazilian'), array('submit' => '')); ?>
</div>
<div id="nothing_special">
<?php //just to check if language has been changed after using dropdown box ?>
<?php echo Yii::app()->language."<br/>".Yii::app()->sourceLanguage; ?>
</div>
<?php echo CHtml::endForm(); ?>[/font]
4- In ../protected/views/layouts/main.php I’ve putted the code bellow (before $content line):
[font=“Courier New”] <?php $this->widget(‘LangBox’); // ac? change user’s language ?>
[/font]
All files cited are in UTF-8 enconde.
I can see the dropDown Box, and be able to change the language options.
But whatever I do that (choosing any different language of en_us), the current page takes an brief while refreshing and comes back to en_us (pagination comes back to first page too) as I can see in the form langBox line [font="Courier New"]<?php echo Yii::app()->language."<br/>".Yii::app()->sourceLanguage; ?>[/font]
I have the same problem with the captha not showing after adding a behavior.
You said:
As you can imagine I was wrong, I found out that the right place to put the snipped
code "'behaviors' => array('ApplicationConfigBehavior')," must be
inside 'components'=>array( ... )
instead into the top return array( ... ) of (../protected/config/main.php) file.
Captcha works fine now.
I belief that is wrong.
The reason why the captcha is working now, is because the behavior is NOT working any more. I think Behaviour must come BEFORE ‘components’=>array( … )
So I am still looking for a solution to get captcha working.