Hey, guys, I've just read the documentation for error handling using controller/action and now I'm trying to find a way to show the error messages translated.
I know I should do something like this:
<?php
echo ‘Erro ‘, $code , ’ - ’ , Yii::t(’ ?’,$message);
?>
But I couldn't understand the $category parameter in Yii::t($category, $message).
the documentation didn't help me in this case, so, could anybody please give me a hint?
thanks a lot!!!
will
(Phpwindcn)
June 13, 2009, 4:53am
2
As I understand, a category is used for your convenience to group messages in a context, which will server as message filename as well.
Here is a quote from the class references:
Translations in one language are kept as PHP files under an individual subdirectory whose name is the same as the language ID. Each PHP file contains messages belonging to the same category, and the file name is the same as the category name.
thanks Will, but now I have a file/category named error.php, in the same directory as yii.php file (protected/messages/pt_br/), which contains:
<?php
return array (
'Message'=>'Another Message',
);
and I'm using a controller/view error handler:
public function actionerror()
{
if($error=Yii::app()->errorHandler->error)
$this->render('error', $error);
}
My view site/error is:
<br/>
<?php
echo 'Erro ', $code , ' - ' , Yii::t('error','Message');
?>
<br/>
The content is renderized fine, but the message is not translated.
If I add the same translation to the yii.php file I mentioned above, the message is translated .
What I'm doing wrong?
thanks
qiang
(Qiang Xue)
June 13, 2009, 11:38am
4
Did you set your application's language property to be pt_br?
You've to set the language in each controller you want to use Yii::t('','')…
fighted with the same fault yesterday
see: http://www.yiiframew…pic,2648.0.html
my config/main.php
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),
'sourceLanguage'=>'pt_br',
'language'=>'pt-br',
my site controller:
class SiteController extends CController
{
public function init(){
Yii::app()->setLanguage('pt_br');
}
still if I put the message in yii.php file under protected/messages/pt_br and set the view to display
Yii::t('yii','Message'),
the translated message is shown, but with my error.php file it doesn't work.
I made a copy/paste of yii.php and changed the content because I thought it could be a matter of encoding, but no postiive results yet…
your help guys is very appreciated, thanks again!
Solved:
Yii::app()->setLanguage('pt_br');
must be:
Yii::app()->setLanguage('pt-br');
it is a - not a _
thank you very much guys, you're great!!!
cheers!!