Thursday, May 28, 2009

Feedback from TranslateBehavior creator needed

Hello, I have some issues while working with TranslateBehavior. I'll
try get to the point:

There's ArticleVersion model, which have this fields: id, name:
varchar, introduction:text, created:datetime.

I've defined to name and introduction fields to be translatable:
var $actsAs = array('Translate' => array('name', 'introduction'));

Quick adding a new ArticleVersion is made by filling just name field
and submitting, and introduction doesn't need to be fulfilled.

Now, when I go to ArticleVersion edit page - I can't see name I just
filled (it is in i18n table) because TranslateBehavior->beforeSave is
making this query:

SELECT `ArticleVersion`.*, `Article`.*, `ArticleMedia`.*,
`I18n__name`.`content`, `I18n__introduction`.`content`,
`ArticleVersion`.`id` FROM `article_versions` AS `ArticleVersion` LEFT
JOIN `i18n` AS `I18n__name` ON (`ArticleVersion`.`id` =
`I18n__name`.`foreign_key` AND `I18n__name`.`model` = 'ArticleVersion'
AND `I18n__name`.`field` = 'name') LEFT JOIN `i18n` AS
`I18n__introduction` ON (`ArticleVersion`.`id` =
`I18n__introduction`.`foreign_key` AND `I18n__introduction`.`model` =
'ArticleVersion' AND `I18n__introduction`.`field` = 'introduction')
LEFT JOIN `articles` AS `Article` ON (`ArticleVersion`.`article_id` =
`Article`.`id`) LEFT JOIN `article_media` AS `ArticleMedia` ON
(`ArticleVersion`.`article_medium_id` = `ArticleMedia`.`id`) WHERE
`ArticleVersion`.`id` = 80165 AND `I18n__name`.`locale` = 'pol' AND
`I18n__introduction`.`locale` = 'pol' LIMIT 1

It returns no rows, because there's `I18n__introduction`.`locale` =
'pol' in where statement, and the introtuction field is't saved in
Quick add operation.

What I need is `i18n__*`='pol' in ON statement for LEFT JOINS, so not
existing translation is not making any of those troubles.

I found interesting if condition in translateBehavior between lines
162 and 195. It checks if $locale variable is array. If not- it places
`i18n__*` statements in WHERE (my example above).
Otherwise it looks like placing `i18n__*` statements in LEFT JOIN ...
ON clause.

But I don't know how to make $locale variable an array? Tried
Configure::write('Config.language', array('pol'=>'pol')); but it
didn't work.

Just for test I changed else statement in that if statement I'm
referring to from:
http://bin.cakephp.org/saved/46610
to
http://bin.cakephp.org/saved/46611

After that it works as I wanted it to work. But I don't like messing
up with core, and don't now if it broke something some place else.

So I need an advice from somebody who knows what TranslateBehavior's
guts does, or someone who can explain to me how to make
TranslateBehavior to work as I desire (if it's possible at all :))

I'm sorry for long post, and not the best English, and thank You for
Your time :)
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: