Re: Translate Behavior internals

2009-02-09 Thread Sebby

To correctly implement i18n and l10n for your purpose you need first
to create the following MySQL tables:

Categories table:

CREATE TABLE `categories` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`created` INT(10) UNSIGNED NOT NULL,
`updated` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
KEY `created` (`created`),
KEY `updated` (`updated`)
) ENGINE=MyISAM, DEFAULT CHARACTER SET UTF8;

Note that the `name` field is only virtual and should not be present
on table schema.

In case if you use TreeBehavior categories table should be like this:

CREATE TABLE `categories` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`parent_id` INT(10) UNSIGNED,
`lft` INT(10) UNSIGNED NOT NULL,
`rght` INT(10) UNSIGNED NOT NULL,
`created` INT(10) UNSIGNED NOT NULL,
`updated` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
KEY `parent_id` (`parent_id`),
KEY `lft` (`lft`),
KEY `rght` (`rght`),
KEY `created` (`created`),
KEY `updated` (`updated`)
) ENGINE=MyISAM, DEFAULT CHARACTER SET UTF8;

And of course the i18n table:

CREATE TABLE `i18n` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`foreign_key` INT(10) UNSIGNED NOT NULL,
`locale` VARCHAR(6)   NOT NULL,
`model` VARCHAR(255) NOT NULL,
`field` VARCHAR(255) NOT NULL,
`content` MEDIUMTEXT,
PRIMARY KEY (`id`),
KEY `row_id` (`foreign_key`),
KEY `locale` (`locale`),
KEY `model` (`model`),
KEY `field` (`field`)
) ENGINE=MyISAM, DEFAULT CHARACTER SET UTF8;

The php code for Category model is:

?php

class Category extend AppModel {

public $name = 'Category';

public $actsAs = array(
'Translate' = array(
'name'
)
);

}

?

To correctly save a category to database (english and german) the data
array should be like the following (title field value should be an
associative array with locales as keys and titles as values) :

$data = array(
'Category' = array(
'title' = array(
'eng' = 'some english title',
'ger' = 'some german title'
)
)
);

And under the controller use this to save the category:

$this-Category-save($data);

Hope this will help!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Translate Behavior internals

2008-12-23 Thread Oliver Block

Hello everybody,

I wonder if someone could help me with the following problem. I have
this table called categories:

CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(64) NOT NULL,
  `modified` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `created` datetime NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

Now I want to implement i18n and l10n. So I started to use the
Translate Behavior in the Category Model. I created the table from app/
config/sql/i18n.sql.

Everything works ... but not for my purpose.:)

Now the problem: When a person adds a category, e.g. english and
german, I get two new records in the tables categories and i18n.
Actually there should only be ONE category and two translations.

Can anyone give me a hint how to accomplish this? A link to some
documentation would also be fine, as the manual is yet to be written.

Best Regards,

Oliver Block

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---