labelEx with translated value first character shows weird character!?

My label code

in view


<?php echo $form->labelEx($model, Yii::t('translation','Apple')); ?>

in messages


<?php

return array (

'Apple' => '苹果',

);

?>



It shows ȋ�果 instead of 苹果

This is consistent with all browsers.

A bug? Any solution?

are all your files utf8 encoded?

IMHO you should use


<?php echo $form->labelEx($model, 'Apple'); ?>

And, in your model’s attributeLabels():


return array(

    …

    'Apple' => Yii::t('translation','Apple'),

)

The behavior you have is because somewhere Yii won’t find the label for your translated string, so labelEx will use generateAttributeLabel and make the first character uppercase:

From http://www.yiiframework.com/doc/api/1.1/CModel#generateAttributeLabel-detail:

I figured actually this is what i should do


<?php echo $form->labelEx($model, 'Apple', array('label' => Yii::t('translation','Apple'))); ?>

But this could probably be consider a bug if indeed my database field name of Apple is in Chinese word which will be written as


<?php echo $form->labelEx($model, '苹果'); ?>

:rolleyes: