I’ve read over 2 dozen post and still can’t get any message to translate. If someone can point out what I’m doing wrong I’d greatly appreciate it!
main.config
//@var string The language that the application is written in.
'sourceLanguage' => 'en',
//@var string Returns the language that the user is using and the application should be targeted to.
'language' => 'de',
....
'components' => array(
'coreMessages' => array('basePath' => 'protected/messages'),
....
i have a folder path as follows
appRoot/protected/messages/de/countriesTranslation.php
in that it has an array of items to translate
return array(
'Long Name' => 'Long name DE',
);
in my model i have
public function attributeLabels() {
return array(
'long_name' => Yii::t('countriesTranslation', 'Long Name'),
....
I’m obviously doing something wrong just can’t figure it out and it’s driving me nuts! I’ve cleared all cache, cookies, sessions, runtime and assets in desperation as well.
Update: I had it setting the language to en in a on-begin request if the user didn’t select one from a dropdown. This was causing it to always use English.
Needless to say the above is all you have to do to translate a message
Please check tutorial I hope it’s some help.
thanks for the reply!
I am apparently doing it correctly. I created a new webapp and copy and pasted everything verbatim and it worked. Something in my app is making it not translate just don’t know what.
Can you please post the countriesTranslation.php file code?
[size="5"]Suggested solution[/size]
1) create the two files,one of them countriesTranslation.csv file and another one countriesTranslation.php is on message folder
2) write the every translated word using comma separated on csv file
for e.g I tralate the monday in Norwegian charter so I write the code on file
Monday,Mandag,,
please see this image [url="http://puu.sh/bYtDN/23ed0b52db.png"]http://puu.sh/bYtDN/23ed0b52db.png[/url]
3) create the function for write the all word from csv file on countriesTranslation.php
<?php
return UtilityHtml::getMessageCSV2Array(' countriesTranslation');
public static function getMessageCSV2Array($key='', $seperator=',')
{
$file=Yii::getPathOfAlias('webroot').'/protected/messages/'.Yii::app()->language.'/'.$key.'.csv';
$row=0;
$arr = array();
if(file_exists($file)) {
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, $seperator)) !== FALSE) {
$num = count($data);
$row++;
if(isset($data[0]) && isset($data[1])) {
$arr[$data[0]] = $data[1];
}
}
fclose($handle);
}
}
return $arr;
}
and using this syntax
Yii::t('countriesTranslation', 'Monday')
you can translate the word