18n Using a database

Hi there,

  I have been been all over the forum and although I can get the translation to work with language files. I would prefer to use a database. I have the following code

array(‘label’=>Yii::t(‘lang’, ‘MENU_LOGIN’), ‘url’=>array(’/site/login’), ‘visible’=>Yii::app()->user->isGuest)

// English

return array (

 'MENU_HOME' => 'Home',


 'MENU_ABOUT' => 'About',


 'MENU_CONTACT' => 'Contact',


 'MENU_LOGIN' => 'Login',


 'MENU_CUSTOMERS' => 'Customers',


 'MENU_USERS' => 'Users',


 'MENU_WORKFLOW' => 'Workflow',


 'MENU_LANG' => 'Language',


 'MENU_LOGOUT' => 'Logout',

);

and also in messages/fr/lang.php

// French

return array (

 'MENU_HOME' => 'Acceuil',


 'MENU_ABOUT' => 'au sujet de nous',


 'MENU_CONTACT' => 'Contact',


 'MENU_LOGIN' => 'Login',


 'MENU_CUSTOMERS' => 'clients',


 'MENU_USERS' => 'utilisateurs',


 'MENU_WORKFLOW' => 'opérations',


 'MENU_LANG' => 'Language',


 'MENU_LOGOUT' => 'Logout',

);

code in a view file

Yii::t(‘lang’, ‘MENU_HOME’);

All the above works but I need to get this working with a database but I can’t get this working. does anyone have a code example please

Cheers

Clive

I think one solution would be to use CDbMessageSource.

(not tested)

/Tommy

Thanks Tommy forgot to mention that I already tired this. I have created the two tables and I have data in the tables . This is what I have in the main.php file

return array(

'language' => 'fr',  

// application components

'components'=>array(


	'user'=>array(


		// enable cookie-based authentication


		'allowAutoLogin'=>true,


	),


	'messages' => array( 


                  'class' => 'CDbMessageSource'),


	// uncomment the following to enable URLs in path-format


	/*

Is there anything else to put in the messages section please. I am assuming that all the code in the view that I have would remain the same

Yii::t(‘lang’, ‘MENU_HOME’);

Any Ideas please?

Cheers

Clive