Trying to get my head round CakePHP 2's Translate behaviour and failing at the creation of content step.
We're trying to get translations working based on the subdomain the site is accessed on. So en.example.com will be the English site and fr.example.com the French. The locale is then set in bootstrap by checking the HTTP host:-
switch ($_SERVER['HTTP_HOST']) {
case 'fr.example.com':
Configure::write('Config.language', 'fre');
break;
case 'en.example.com':
default:
Configure::write('Config.language', 'eng');
break;
}
I've created the i18n table using the i18n shell script and tested that the above config works for retrieving data if I manually add some translated fields to the table.
We have a page model that we want to translate the title and body of:-
class Page extends AppModel {
public $actsAs = array(
'Translate' => array(
'title',
'body'
)
);
The idea is that when a page is created on a subdomain we want it to create versions of the page for each language. So if a page is created on en.example.com a French version is created at the same time. I've attempted to do this in the Page::afterSave() method, but it is not saving the alternative translation to the i18n table:
public function afterSave($created, $options=array()) {
parent::afterSave($created, $options);
if ($created) {
$this->locale = $this->locale=='eng' ? 'fre' : 'eng';
$this->save($this->data, false, array('callbacks' => false));
}
return;
}
Any suggestions?