Je suis aussi en train de développer un site en Multilingue et j'ai beaucoup de mal à faire ce que je veux.
En ce qui te concerne, j'ai trouvé deux solutions, pas forcément les meilleurs mais on fait avec ce qu'on a ^^
-
Si tu as déjà du contenu, tu peux créer une fonction qui repassera sur tous tes posts pour les ajouter dans la table i18n de façon à ce que tes requêtes ne soient pas vide :
function regenerate()
{
$this->Article->Behaviors->disable('Translate');
$out = $this->Article->find('all', array('recursive'=>-1, 'order'=>'id'));
$t = $b = 0;
foreach($out as $v){
$title'locale'] = 'aze';
$title'model'] = 'Article';
$title'foreign_key'] = $v'Article']'id'];
$title'field'] = 'title';
$title'content'] = $v'Article']'title'];
if($this->Article->I18n->create($title) && $this->Article->I18n->save($title)){
$t++;
}
$body'locale'] = 'aze';
$body'model'] = 'Article';
$body'foreign_key'] = $v'Article']'id'];
$body'field'] = 'body';
$body'content'] = $v'Article']'body'];
if($this->Article->I18n->create($body) && $this->Article->I18n->save($body)){
$b++;
}
}
}
-
Sinon, de mon coté, j'ai crée un Behavior qui check chaque requete pour voir s'il trouve une traduction, sinon, il retourne le champs par défaut. C'est encore en béta, n'hésitez pas à m'aider à le peaufiner ;)
<?php
class CheckTranslateBehavior extends ModelBehavior{
public function setup(Model $model,$options = array()) {
if (Configure::read('Config.i18n_active') == true) {
$model->Behaviors->load('Translate', $options'fields']);
}
}
public function afterFind(Model $model, $data) {
if (!$model->Behaviors->enabled('Translate') && Configure::read('Config.i18n_active') == true) {
// Tell it to start doing so
$model->Behaviors->enable('Translate');
}
return $data;
}
public function checkTranslate(Model $model, $id) {
if (Configure::read('Config.i18n_active') == false) {
$model->Behaviors->unload('Translate');
return false;
}
$count = $model->find('count', array(
'conditions' => array($model->name.'.id' => $id)
));
if ($count == 0) {
$model->Behaviors->disable('Translate');
return false;
} else {
return true;
}
}
}
Donc dans mon model Post, je fais un ActsAs de cette façon :
var $actsAs = array(
'CheckTranslate' => array(
'fields' => array('title', 'slug', 'body', 'meta_description', 'meta_keywords')
),
);
Et dans mon PostsController.show(), avant le find, j'appel :
$this->Post-> checkTranslate($id);
Voilà voilà, j'espère être assez clair :)
Si tu as des idées pour mon post, n'hésites pas !!!
http://www.grafikart.fr/forum/topic/5649