I’m pulling out multiline strings from mysql DB and trying to use Yii:t() for mulit-language, but something is not working and I can figure out why.
I have on the page (output 1)
<p><?php Yii::t('messages', 'record2
line2');?><p>
then I have also (output 2):
<?php
$testVar = 'record2
line2';
?>
<p><?php echo Yii:t('messages', $testVar);?></p>
then I also have (output 3 & output 4):
<p><?php echo CHtml::encode(Yii::t('messages', $data->description)); ?></p>
<p><?php echo Yii::t('messages', $data->description); ?></p>
Where $data->description is TEXT field in a record in a mysql db of string value:
record2
line2
The messages.php looks like this:
<?php
return array (
'record2
line2' => '紀錄2
第二行',
);
When I then do a language switch, output 1 & 2 works fine, but output 3 & 4 fails to pull the translated text strings from the message.php file.
I looked at the html output and they, to me, all look identical, even the carriage return characters are the same.
The html output of the untranslated:
<p>record2
line2</p>
<p>record2
line2</p>
<p>record2
line2</p>
<p>record2
line2</p>
The html output of the translated:
<p>紀錄2
第二行</p>
<p>紀錄2
第二行</p>
<p>record2
line2</p>
<p>record2
line2</p>
But if I try to do
$testVar == CHtml::encode(Yii::t('multiline', $data->description))
$testVar == Yii::t('multiline', $data->description)
$testVar == $data->description
they would all return false!
At first I though maybe the type came out different, so I used gettype() on $testVar, $data->description, Yii::t(‘messages’, $data->description), CHtml::encode(Yii::t(‘multiline’, $data->description)), and they are all strings.
I’ve also tried this where the data is single line instead of multiple lines, and everything works just fine.
Can someone help me figure out what’s going on and how to fix this so output 3 & 4 would correctly show the translated text?
Thanx in advance.