Damn copy&paste... the last lines of the function are missing:

                @ignore_user_abort((bool) $this->runtime[$model->name]
['ignoreUserAbort']);
                unset($this->runtime[$model->name]['ignoreUserAbort']);
        }

On 25 jul, 18:34, Gorka <[EMAIL PROTECTED]> wrote:
> In case it helps anyone, this is the solution I've come up with.
> Please keep in mind that this is my own personal solution and may
> conflict with active development by the core team.
>
> On your edit/add views you must use plain html instead of the form
> helper, because it won't generate data[Model][Field][locale] names no
> matter what you try. IMHO, this is something to look into, because it
> also adds difficulties dealing with file input arrays and the like.
> Anyhow, the input fields should look like:
>
> <input type="text" name="data[Model][Field][locale]"
> id="ModelFieldLocale" />
>
> I've rewritten the afterSave() function of TranslateBehaviour like
> follows to allow working with the new field arrays. This should
> probably better be pasted somewhere else, feel free to do so if you
> feel like it.
>
>         function afterSave(&$model, $created) {
>                 $locale = $this->_getLocale($model);
>
>                 if (empty($locale) || is_array($locale) || 
> empty($this->runtime[$model->name]['beforeSave'])) {
>
>                         return true;
>                 }
>                 $tempData = $this->runtime[$model->name]['beforeSave'];
>                 unset($this->runtime[$model->name]['beforeSave']);
>
>                 $conditions = array('model' => $model->name,
>                                                         'row_id' => 
> $model->id);
>
>                 if ($created) {
>                         foreach ($tempData as $field => $value) {
>                             if (!is_array($value)) {
>                                 $value = array($locale=>$value);
>                             }
>
>                             foreach ($value as $lang=>$content) {
>                                  $this->_model->Content->create();
>                                  
> $this->_model->Content->save(array('I18nContent' =>
> array('content'=>$content)));
>
>                                  $this->_model->create();
>                                  $this->_model->save(array('I18nModel' => 
> am($conditions,
> array(
>                                                                               
>    'locale'
> => $lang,
>
> 'i18n_content_id' => $this->_model->Content->getInsertID(),
>                                                                               
>    'field' =>
> $field))));
>                             }
>                         }
>                 } else {
>                         $this->_model->recursive = -1;
>                         $translations = $this->_model->findAll($conditions, 
> array('field',
> 'i18n_content_id', 'locale'));
>                         $values = Set::extract($translations, 
> '{n}.I18nModel');
>
>                         foreach ($values as $translation) {
>                             $field = $translation['field'];
>                             if (array_key_exists($field, $tempData)) {
>                                 if (!is_array($tempData[$field])) {
>                                     $tempData[$field] = 
> array($locale=>$tempData[$field]);
>                                 }
>                                 if (array_key_exists($translation['locale'],
> $tempData[$field])) {
>                                     $this->_model->Content->create();
>                                     
> $this->_model->Content->save(array('I18nContent' =>
> array(
>                                                                              
> 'id'=>
> $translation['i18n_content_id'],
>                                                                              
> 'content'=>
> $tempData[$field][$translation['locale']])));
>                                 }
>                             }
>                         }
>
>                 }
>
> There is sure plenty of room for improvement, but it works for me.
>
> I'm still trying to figure out how to define a default locale and
> dealing with the different locales set by IE7 & Firefox (spa/es-es).
> This last issue is really annoying, as it hides one's records from the
> other when using locale autodetection.
>
> Comments, improvements and suggestions are more than welcome :)
>
> On 25 jul, 14:33, Gorka <[EMAIL PROTECTED]> wrote:
>
>
>
> > I tried a similar approach and most likely will end up using it due to
> > time constraints for the project. Still, i18n support is a great step
> > in Cake's maturity road, and I'd love to make it work even if it was
> > in a not-so-elegant way. In fact, maybe Cake Foundation may study
> > donation-promoted development. I'd be more than happy to donate to see
> > this functionallity working!
>
> > On 25 jul, 01:56, oleonav <[EMAIL PROTECTED]> wrote:
>
> > > On Jul 24, 12:09 am, Gorka <[EMAIL PROTECTED]> wrote:
>
> > > > Actually, $form->input('TransName.eng.content') renders something like
> > > > this for me:
>
> > > > <input name="data[TransName][content]" type="text" value=""
> > > > id="TransNameContent" />
>
> > > > This is obviously not very useful when editing multiple languages at
> > > > the same time (mostly in the admin area for defining name,
> > > > description, etc... of an item). Has anyone found a method for editing
> > > > multiple languages at the sameview?
>
> > > Yes, I did find this out to. Not very useful.
>
> > > > Oleonav, did you manage to get any closer to a satisfying solution?
>
> > > No, I did not. Not in the cake 1.2 way for that matter. Maybe some of
> > > the core developers would be so nice to contribute on this subject.
>
> > > Anyway, I'm working on a different approach to i18n. It does not use a
> > > 'global' i18n & i18n_content table. It stores translations in the same
> > > table as the main, default language.
>
> > > For example a article table:
> > > id
> > > article_id
> > > locale
> > > ...
> > > title
> > > content
>
> > > For the main article, in the default language, the field id & article
> > > id have the same value. Locale is set to the default locale string.
> > > Translations have their own id. The  article_id is the same as the id
> > > of the main default record. Each translation has it's own locale
> > > string. The combination of article_id & locale is defined as unique in
> > > the database.
>
> > > Model assoc's:
> > > var $belongsTo = array(
> > >    'MotherArticle' => array('className' => 'Article',
> > >         'foreignKey' => 'article_id',
> > >         );
>
> > > var $hasMany = array(
> > >    'ChildArticle' => array('className' => 'Article',
> > >         'foreignKey' => 'article_id'
> > >         );
>
> > > I have added a function to the main AppModel to fetch the article in
> > > the preferred translation if available.
>
> > > function readTranslated($fields=null,$id,$lang=null){
> > >    $res = $this->read($fields,$id);
> > >    $childs = 'Child' . $this->name;
> > >    if($res && $lang && is_array($res[$childs])){
> > >       foreach($res[$childs] as $trans){
> > >         if($trans['locale'] == $lang){
> > >            $resTrans = $trans;
> > >            $resTrans['translated'] = 'yes';
> > >         }
> > >      }
> > >    }
> > >    if(isset($resTrans)){
> > >      $res[$this->name] = $resTrans;
> > >    }
> > >    elseif($res != null){
> > >      $res[$this->name]['translated'] = 'no';
> > >    }
>
> > >    return $res;
>
> > > }
>
> > > In the view action of the article controller I use the following
> > > function $this->Article->readTranslated(null,$id,'eng') for example to
> > > fetch the article in the prefered language, if available.
>
> > > I'm now busy coding the add & edit actions. Having some trouble with
> > > validation....
>
> > > This is work in progress. I will share my thoughts / solution when I'm
> > > satisfied- Ocultar texto de la cita -
>
> > - Mostrar texto de la cita -- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to