Localization/translation from database

Hello,

I was not able to understand, from the current documentation, how does the translations works from the database…  ::)

I want to use as source language the english (en_us) language and as target language the italian language (it_it) …

In the config file I've specified the italian language:

'language'=>'it_it'

and in my database I've created the two tables as explained here:

http://www.yiiframew…DbMessageSource

But then I don't know how to set the type of my message source to "CDbMessageSource":

Quote

By default, the type of this message source is CPhpMessageSource and the base path for storing the PHP translation files is protected/messages.

How can I do that? By now I've been able to load string from the:

protected/messages/it_it/CategoryName.php file …

but not from the database.

also is not clear to me how data should be entered in the two database tables; an example in the documentation would make it faster to understand…

anyway here is my test db tables (with contents):

CREATE TABLE IF NOT EXISTS `Message` (


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


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


  `translation` text,


  PRIMARY KEY  (`id`,`language`)


) ENGINE=MyISAM DEFAULT CHARSET=utf8;








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


(1, 'it_it', 'Esci'),


(1, 'en_us', 'Logout');





-- --------------------------------------------------------











CREATE TABLE IF NOT EXISTS `SourceMessage` (


  `id` int(11) NOT NULL,


  `category` varchar(32) default NULL,


  `message` text,


  PRIMARY KEY  (`id`)


) ENGINE=MyISAM DEFAULT CHARSET=utf8;








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


(1, 'main', 'Logout');

Thanks.

bye,

Giovanni.

Both CPhpMessageSource and CDbMessageSource are application components. That means, you just need to configure the 'messages' application component as follows:



return array(


   'components'=>array(


      'messages'=>array(


          'class'=>'CDbMessageSource',


      ),


   ),


);


Unlike CPhpMessageSource, Yii doesn't have a tool to help you enter messages to be translated into the DB tables. You need to develop such a tool by yourself. You may refer to "yiic message" command.

Quote

Unlike CPhpMessageSource, Yii doesn't have a tool to help you enter messages to be translated into the DB tables. You need to develop such a tool by yourself. You may refer to "yiic message" command.

Thanks (worked at first try ;D), I suggest you to add that small example to the documentation too as it helps to better understands how Yii works for newbies like me ;)

About the tool for translating yiic messages in the DB… if you are interested I can try to develop it as something “standalone” that can be used for translate projects in general and then send the source to you (BSD License)  ;)

let me know. thanks.

Giovanni.

Will do.

Regarding the tool, I suggest you create and share it as an extension (a yiic command). Thanks!