Internationalization: No Translation At All

Hi all,

I’m looking to internationalize my website, thought the use of the CDbMessageSource class. I’ve created the 2 tables “sourceMessages” and “translatedMessages”.

I’ve updated the database connection information in “protected/config/main.php” file.

This is my view’s code:


<?php


$this->pageTitle=Yii::app()->name . ' - Chants';

$this->breadcrumbs=array(

	'Chants',

);


echo "<h1>Chants</h1>";

echo Yii::t('Menu','J’aime mieux avoir Christ que l’or fabuleux, J’aime mieux avoir Christ qu’un palais somptueux, J’aime mieux avoir Christ que la renommée, J’aime mieux qu’il me guide par sa main percée');

?>

But I don’t get the expected translation.

I’ve read this and that.

but I think I’m missing something.

Have you red this too?

Hi Roman Solomatin. I didn’t red the article your message is pointing to. This article is talking about “Setting and maintaining the language in Application (i18n)”. I think I did already set the languages as follow:

in protected/config/main.php I’ve this:


'sourceLanguage' => 'en',

'language' => 'fr',

and this is how I did set the database configuration:


'db' => array(

			'class' => 'CDbMessageSource',

			'connectionString' => 'mysql:host=localhost;dbname=internationalisation',

			'emulatePrepare' => true,

			'username' => '*************',

			'password' => '******************',

			'charset' => 'utf8',

		),

Maybe I didn’t get the point; so can you please explain more, or could anyone else help me to find the issue I’m missing? Thank you.

Anyone has an idea for me?

I have followed this article for language selection and multilangual setting. I have no error. But there is no translation. When i put this into the view code like this:


echo Yii::t('Menu','tata');

I have as output exactly


tata

Here is the view code:


<?php


$this->pageTitle=Yii::app()->name . ' - Chants';

$this->breadcrumbs=array(

	'Chants',

);


echo "<h1>Chants</h1>";

echo Yii::t('Menu','tata');

?>

Here is the protected/viewslayouts/main.php code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>


</head>


<body>


<div class="container" id="page">


	<div class="backgroundGeneral">

		<div id="mainmenu">

			<?php $this->widget('zii.widgets.CMenu',array(

				'items'=>array(

					array('label'=>'Accueil', 'url'=>array('/site/index')),

					array('label'=>'Curriculum vitae', 'url'=>array('/mespagesweb/cv', 'view'=>'cv')),

					array('label'=>'Enseignement et recherche', 'url'=>array('/mespagesweb/enseignementrecherche', 'view'=>'enseignementrecherche')),

					array('label'=>'Déconnexion ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest),

					array('label'=>'Forum', 'url'=>array('/site/pages/introduction.php')),

					array('label'=>'Divers', 'url'=>array('/mespagesweb/introduction')),

					array('label'=>'Contact', 'url'=>array('/site/contact')),

					array($this->widget('application.components.widgets.languageSelector')),

				),

			)); ?>


		</div><!-- mainmenu -->


		<?php echo $content; ?>


		<div class="footer">

			Copyright &copy; <?php echo "2003-", date('Y'); ?><br/>

			Tous droits réservés.<br/>

		</div><!-- footer -->

	</div><!--backgroundGeneral-->


</div><!-- page -->


</body>

</html>

Thanks

Do you have a file named Menu.php in your protected/messages/fr folder?

The first argument in Yii::t() function (in case of CPhpMessageSource) is the file name (without the extension part).

Hi Roman,

I don’t have a file named Menu.php in protected/messages/fr folder, because I’am using CDbMessageSource module. With CDbMessageSource, according my readings, the first argument in Yii::() function is one of the value of sourceMessages.category, sourceMessages being the table where original messages are stored.

I haven’t used CDbMessageSource myself, but do you have “Menu” category in your sourceMessages table?

And do you have messages component configured to use CDbMessageSource in your configuration?

Yes. This is my database structure:


--`sourcesMessages` table structure


CREATE TABLE IF NOT EXISTS `sourceMessages` (

  `id` int(11) NOT NULL,

  `category` varchar(32) DEFAULT NULL,

  `message` text,

  PRIMARY KEY (`id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1;


-- `sourceMessages` table content


INSERT INTO `sourceMessages` (`id`, `category`, `message`) VALUES

(2, 'Menu', 'Enseignement et recherche'),

(1, 'Menu', 'Curriculum vitae'),

(3, 'Menu', 'Forum'),

(4, 'Menu', 'Divers'),

(5, 'Menu', 'Contact');


--`translatedMessages` table structure




CREATE TABLE IF NOT EXISTS `translatedMessages` (

  `id` int(11) NOT NULL DEFAULT '0',

  `language` varchar(16) NOT NULL DEFAULT '',

  `translation` text,

  PRIMARY KEY (`id`,`language`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1;


-- `translatedMessages` table content


INSERT INTO `translatedMessages` (`id`, `language`, `translation`) VALUES

(1, 'en', 'Curriculum vitae'),

(2, 'en', 'Teaching and research'),

(3, 'en', 'Forum'),

(4, 'en', 'Miscellanous'),

(5, 'en', 'Contact');

Regarding internationalization settings, and based on the reading1, and reading2, this is what I have:

-framework/i18n/ CDbMessageSource.php

-protected/components/HttpRequest.php

-protected/components/BeginRequest.php

-protected/components/widgets/languageSelector.php

-protected/components/widgets/views/languageSelector.php

-settings in protected/config/main.php

The messages in sourceMessages table need to be in sourceLanguage, which you have defined as "en" in your configuration.

And messages in translatedMessages table need to be in language, which you have defined as "fr" in your configuration.

As you have pointed out in your first reply:


'sourceLanguage' => 'en',

'language' => 'fr',

It is true that I stated that. But I have tried both, this:


'sourceLanguage' => 'en',

'language' => 'fr',

and that


'sourceLanguage' => 'fr',

'language' => 'en',



But there is no change in the output. When I type this


echo Yii::t('Menu','tata');

I sill have as output


tata

.

I’m asking myself if the view is making any connection with the database.

Hmm, I’m running out of ideas.

Maybe if you could try to get translations to work using CPhpMessageSource first?

And after that try CDbMessageSource?


'sourceLanguage' => 'fr',

'language' => 'en',



and display your view in both languages. Is it the same?