On further testing I found something strange. I setup a dummy Model Multiline with just a description field (TEXT) with only one record. In a view file, I have a static Yii::t multi-line entry and a dynamic Yii::t echo statement. The data in the description is:
line 1
line2
I put together a view file with a static Yii::t command:
<?php echo Yii::t('messages', 'line 1
line2');?>
And a dynamic Yii::t multi-line command:
<?php echo Yii::t('messages', $data->description); ?>
where $data->description pulls
line 1
line2
out from the database.
These two Yiic::t are on the same view file, when running through the yiic message with the controller behavior I mentioned before. I get a fake db_string.php file as intended that looks like this:
<p><?php echo Yii::t('multiline', 'record2
line2'); ?></p>
and the multiline.php message file looks like this:
<?php
/**
* Message translations.
*
* This file is automatically generated by 'yiic message' command.
* It contains the localizable messages extracted from source code.
* You may modify this file by translating the extracted messages.
*
* Each array element represents the translation (value) of a message (key).
* If the value is empty, the message is considered as not translated.
* Messages that no longer need translation will have their translations
* enclosed between a pair of '@@' marks.
*
* Message string can be used with plural forms format. Check i18n section
* of the guide for details.
*
* NOTE, this file must be saved in UTF-8 encoding.
*
* @version $Id: $
*/
return array (
'record2
line2' => '',
);
If I enter a value, for example, in Chinese like below and perform a language switch:
return array (
'record2
line2' => '測試',
)
Then the static one translation works but not the dynamic one.
I then trigger another yiic message by running an update on the model. The db_strings.php file stays the same, but the multiline.php message file now becomes:
<?php
/**
* Message translations.
*
* This file is automatically generated by 'yiic message' command.
* It contains the localizable messages extracted from source code.
* You may modify this file by translating the extracted messages.
*
* Each array element represents the translation (value) of a message (key).
* If the value is empty, the message is considered as not translated.
* Messages that no longer need translation will have their translations
* enclosed between a pair of '@@' marks.
*
* Message string can be used with plural forms format. Check i18n section
* of the guide for details.
*
* NOTE, this file must be saved in UTF-8 encoding.
*
* @version $Id: $
*/
return array (
'record2
line2' => '',
'record2
line2' => '@@@@',
);
I checked for invisible characters and both strings keys are identical! Why is one being identified as not used? What’s going on?
To narrow down the problem, I started over (clean db_strings.php and multiline.php message file). I removed the static Yii::t entry from the view and run update to trigger the yiic message. And sure enough, after two updates, I got the same result (two duplicated entries and one identified as not used).
Can anyone help? I’m really stumped. It seems so close yet I just don’t get it…