views:

2077

answers:

2

There is no documentation on cakephp.org and I am unable to find one on google. Please link me some documentation or supply one!

A: 

well you can check out this link... Transaction behavior

I am lookin for more, I'll keep u posted as I get other one. hope this helps.

shaleen mohan
Transaction != Translation
Alexander Morland
maybe it does if you translate it :)
reefnet_alex
It made me laugh
Sybiam
maybe he was thinking at this one: http://book.cakephp.org/view/1328/Translate
Duncan Benoit
+8  A: 

The translate behavior is another of CakePHP's very useful but poorly documented features. I've implemented it a couple of times with reasonable success in multi-lingual websites along the following lines.

Firstly, the translate behavior will only internationalize the database content of your site. If you've any more static content, you'll want to look at Cake's __('string') wrapper function and gettext (there's some useful information about this here)

Assuming there's Contents that we want to translate with the following db table:

CREATE TABLE `contents` (
    `id` int(11) unsigned NOT NULL auto_increment,
    `title` varchar(255) default NULL,
    `body` text,
  PRIMARY KEY  (`id`),
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

The content.php model then has:

var $actsAs = array('Translate' => array('title'   => 'titleTranslation',
         'body'    => 'bodyTranslation'
         ));

in its definition. You then need to add the i18n table to the database thusly:

CREATE TABLE `i18n` (
  `id` int(10) NOT NULL auto_increment,
  `locale` varchar(6) NOT NULL,
  `model` varchar(255) NOT NULL,
  `foreign_key` int(10) NOT NULL,
  `field` varchar(255) NOT NULL,
  `content` mediumtext,
  PRIMARY KEY  (`id`),
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

Then when you're saving the data to the database in your controller, set the locale to the language you want (this example would be for Polish):

$this->Content->locale = 'pol';
$result = $this->Content->save($this->data);

This will create entries in the i18n table for the title and body fields for the pol locale. Finds will find based on the current locale set in the user's browser, returning an array like:

[Content]
  [id]
  [titleTranslation]
  [bodyTranslation]

We use the excellent p28n component to implement a language switching solution that works pretty well with the gettext and translate behaviours.

It's not a perfect system - as it creates HABTM relationships on the fly, it can cause some issues with other relationships you may have created manually, but if you're careful, it can work well.

David Heggie
thanks. even finding out the i18n table's name and fields was hard.. talk about hidden functionality..
Alexander Morland