Я ищу лучшее решение для использования Translate Behavior / i18n для связанных моделей (hasOne, hasMany или HABTM). CakePHP 1.x и 2.x не поддерживают это.
Мое решение очень уродливое, но работает:
if(Configure::read('Config.language') !== DEFAULT_LANGUAGE) {
$this->{$this->modelClass}->locale = array(Configure::read('Config.language'), DEFAULT_LANGUAGE);
if(is_array($this->{$this->modelClass}->belongsTo)) {
foreach($this->{$this->modelClass}->belongsTo as $relation => $model) {
$this->{$this->modelClass}->$model['className']->locale = array(Configure::read('Config.language'), DEFAULT_LANGUAGE);
}
} elseif(is_array($this->{$this->modelClass}->hasOne)) {
foreach($this->{$this->modelClass}->hasOne as $relation => $model) {
$this->{$this->modelClass}->$model['className']->locale = array(Configure::read('Config.language'), DEFAULT_LANGUAGE);
}
} elseif(is_array($this->{$this->modelClass}->hasMany)) {
foreach($this->{$this->modelClass}->hasMany as $relation => $model) {
$this->{$this->modelClass}->$model['className']->locale = array(Configure::read('Config.language'), DEFAULT_LANGUAGE);
}
}
} else {
$this->{$this->modelClass}->locale = DEFAULT_LANGUAGE;
}
Может быть, у вас есть лучшее решение, и вы можете показать мне :)