Yii:t() now working in view

(Edit: sorry for the typo in topic name, it should have been "not working")

Hello,

Did you ever have problem with calling Yii:t() from view? Becasue I have view where i use:


<h1><?php echo Yii::t('app','Welcome'); ?></h1>

but when executed it prints nothing (in html source of the page it just shows: <h1></h1>

All other functions, like when i tried to print the languages:


<h1><?php echo Yii::app()->language; echo Yii::app()->sourceLanguage; ?></h1>

in the same view work without problem. Even when i try put this in controller:


public function actionIndex()

{

        $this->render('index',array(

	     'var'=>Yii::t('app', 'Welcome')

        ));

}

and this in view:


<h1><?php echo $var; ?></h1>

it prints translated message SUCCESSFULLY.

So the problem is i cannot run Yii::t() directly from view,tho it works when calling in controller. And sending all messages from Controller to View seem like an unncessary workaround, because according to the guide and other examples over the internet it should work. I am trying to solve this for couple of hours, but it still may be, that I am missing something …did somebody experienced the same problem?

Thanks,

Matej

hi

in protected/message foler one en_us folder.

in this folder u have to make one file like app.php than in this

return array(‘TXT_M’ => ‘Message’);

Now in ur project u can use Yii::t(‘app’, TXT_M);

Thanks

Oh,

I made stupid mistake, i forgot to put echo before Yii:t().

Thanks for replies,

Maybe some day will somebody make the same dumb mistake and this would help :P

Thanks,Matej

Sorry to bump an old post. I’m having a slightly different issue with Yii::t() in a view in Yii 1.1.12. I’m returning a form via ajax. In the controller I’m using renderPartial on the “create” template, which gii generated. In the _form template, I’m trying to do this:




<div id="submit-dialog" class="hidden">

<?php echo Yii::t('app','Submitting form.'); ?>

</div>



The Ajax response I get back is:




<h1>CException</h1>

<p>Property "CPhpMessageSource.extensionBasePaths" is not defined. (/usr/local/share/yii-1.1.12.b600af/framework/base/CComponent.php:174)</p><pre>#0 /usr/local/share/yii-1.1.12.b600af/framework/YiiBase.php(222): CComponent->__set('extensionBasePa...', Array)

#1 /usr/local/share/yii-1.1.12.b600af/framework/base/CModule.php(387): YiiBase::createComponent(Array)

#2 /usr/local/share/yii-1.1.12.b600af/framework/YiiBase.php(579): CModule->getComponent('messages')

#3 <projectpath>/protected/views/post/_form.php(10): YiiBase::t('app', 'Submitting form...')

#4 /usr/local/share/yii-1.1.12.b600af/framework/web/CBaseController.php(127): require('/home/mlemay/pu...')

#5 /usr/local/share/yii-1.1.12.b600af/framework/web/CBaseController.php(96): CBaseController->renderInternal('/home/mlemay/pu...', Array, true)

#6 /usr/local/share/yii-1.1.12.b600af/framework/web/CController.php(870): CBaseController->renderFile('/home/mlemay/pu...', Array, true)

#7 <projectpath>/protected/views/post/create.php(18): CController->renderPartial('_form', Array)

#8 /usr/local/share/yii-1.1.12.b600af/framework/web/CBaseController.php(127): require('/home/mlemay/pu...')

#9 /usr/local/share/yii-1.1.12.b600af/framework/web/CBaseController.php(96): CBaseController->renderInternal('/home/mlemay/pu...', Array, true)

#10 /usr/local/share/yii-1.1.12.b600af/framework/web/CController.php(870): CBaseController->renderFile('/home/mlemay/pu...', Array, true)

#11 <projectpath>/protected/controllers/PostController.php(113): CController->renderPartial('create', Array, false, true)

#12 /usr/local/share/yii-1.1.12.b600af/framework/web/actions/CInlineAction.php(50): PostController->actionAjaxCreate()

#13 /usr/local/share/yii-1.1.12.b600af/framework/web/CController.php(309): CInlineAction->runWithParams(Array)

#14 /usr/local/share/yii-1.1.12.b600af/framework/web/filters/CFilterChain.php(134): CController->runAction(Object(CInlineAction))

#15 /usr/local/share/yii-1.1.12.b600af/framework/web/CController.php(1117): CFilterChain->run()

#16 /usr/local/share/yii-1.1.12.b600af/framework/web/filters/CInlineFilter.php(59): CController->filterPostOnly(Object(CFilterChain))

#17 /usr/local/share/yii-1.1.12.b600af/framework/web/filters/CFilterChain.php(131): CInlineFilter->filter(Object(CFilterChain))

#18 /usr/local/share/yii-1.1.12.b600af/framework/web/filters/CFilter.php(41): CFilterChain->run()

#19 /usr/local/share/yii-1.1.12.b600af/framework/web/CController.php(1146): CFilter->filter(Object(CFilterChain))

#20 /usr/local/share/yii-1.1.12.b600af/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))

#21 /usr/local/share/yii-1.1.12.b600af/framework/web/filters/CFilterChain.php(131): CInlineFilter->filter(Object(CFilterChain))

#22 /usr/local/share/yii-1.1.12.b600af/framework/web/CController.php(292): CFilterChain->run()

#23 /usr/local/share/yii-1.1.12.b600af/framework/web/CController.php(266): CController->runActionWithFilters(Object(CInlineAction), Array)

#24 /usr/local/share/yii-1.1.12.b600af/framework/web/CWebApplication.php(283): CController->run('ajaxCreate')

#25 /usr/local/share/yii-1.1.12.b600af/framework/web/CWebApplication.php(142): CWebApplication->runController('post/ajaxCreate...')

#26 /usr/local/share/yii-1.1.12.b600af/framework/base/CApplication.php(162): CWebApplication->processRequest()

#27 <projectpath>/index.php(15): CApplication->run()

#28 {main}</pre>



So I found an issue with a previous version of yii #2624 on code.google.com (I can’t submit or preview this post if I include a link directly: I get a message about not being able to include links and page just dies). I checked my config/main.php and found this:




        'messages' => array(

            'extensionBasePaths' => array(

                'giix' => 'ext.giix.messages'

            )

        ),



Clearly, the referenced issue isn’t relevant (I’m not writing an extension). But I tried contriving ‘app’ => ‘application.messages’ which didn’t appear to have any effect.

I also took a cue from Pravin’s suggestion and tried creating an app.php file in protected/messages/en_us to no avail.