> > > 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.
I can imagine some solution where you will name these virtual fields
like 'tr_name', but it will require to go through whole app and alter
all find's called with option 'fields'... But it is Hic Sunt Leones
area - TranslateBehavior was not supposed to work that way. Good news
for you is that features lists for CakePHP 1.3 and 2.0 are not closed
yet, so everyone is welcome open enhancement ticket at thechaw.com or
express himself at http://groups.google.com/group/cake-php/browse_thread/thread/134b180ce477b9ef/12f97d91695be484
:-)
Migration of existing data to i18n table is easy in shell, like
var $uses = array('ArticleVersion');
function main() {
if ($this->ArticleVersion->hasField('name') && $this-
>ArticleVersion->hasField('introduction')) {
$I18n =& $this->ArticleVersion->translateModel();
$this->ArticleVersion->unbindTranslation();
$data = $this->ArticleVersion->find('all', array('fields' =>
array('id', 'name', 'introduction')));
//use either foreach, or saveAll() somehow to save data
through $I18n model
//drop name and introduction fields in schema and clear tmp/
cache/models content
}
$this->out('Done.');
}
> > 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).
Real problem is that in 1.2, behaviors are still pretty limited in
sense what they can do with model, like changes in schema property. So
handling default values for virtual fields, if can not be generalized
in behavior to satisfy everyone, is still work for some simple
beforeSave() implementation in model or AppModel.
> > 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') );
No, that's wrong.
a) 'Config.language' in Configure singleton or session is not supposed
to hold locale, it is for language (see maps in L10n class).
b) 'Config.language' has to be string, it is used by i18n functions __*
()
> 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?
Yes, but see my previous note. Call Configure::write('App.locales',
array('pol', 'eng')); in bootstrap.php and use 'App.locales' in
AppModel constructor.
> .... 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
I am just saying how is 'default translation' supposed to work
currently. Usage by some way not covered in test cases is on your own
risc now, and for future too :-)
--~--~---------~--~----~------------~-------~--~----~
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:
Post a Comment