Sunday, May 31, 2009

Re: Feedback from TranslateBehavior creator needed

Hello Jitka :) I remember You from our discussion about my performance
trick in cake.1.1 ;)

On 30 Maj, 03:41, "jitka (poLK)" <slunii...@gmail.com> wrote:
> > 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'));
>
> Table for ArticleVersion model should not contain fields 'name' and
> 'introduction', these fields are virtual.

I'd love too. But I'm not creating new App with i18n, I'm trying to
make existing App to be i18n'ed,
So I need to leave this fields because they suppose to be my default
translation as long, as translations
are not present.

>
> > Quick adding a new ArticleVersion is made by filling just name field
> > and submitting, and introduction doesn't need to be fulfilled.
> > ...
> > 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.
>
> Fastest possible way is save introduction as empty string in Quick add
> operation.

I wanted to avoid that. When I add another field to be translatable -
need to update the Quick add operation, and
supply those translations to all elements (like I described in comment
above). It's not the really my favourite dont-need-to-do-too-much-when-
stuff-changes-because-cake-takes-care-of-that way ;)

>
> > But I don't know how to make $locale variable an array?
>
> From controller, $this->ArticleVersion->locale = array('pol') should
> do the trick,

I think my question should have been "But I don't know how to make
$locale variable an array globally?" ;)

Yes, It seems to be the only way.
But It's rather $this->ArticleVersion->locale = array( Configure::read
('Config.language') );
But I'm quite lazy, and don't want to travel through all my
Controllers and Models, see where I have
{anyModelWithTranslateBehavior}->find(); and supply this code before.

Do you think overriding the constructor in AppModel like this:
function __construct($id=null, $table=null, $ds=null) {
parent::__construct($id, $table, $ds);
$this->locale = array( Configure::read('Config.language') );
}
Is save? It seems to work for me: it finds rows with translation
supplied just for one field and as a bonus: it reads those original
fields (that which should be virtual, but can't be in my case) when
there's no translation. But I don't feel comfortable when messing with
modules Ii don't completely understand :S
--~--~---------~--~----~------------~-------~--~----~
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: