Part 2: Controller
<?php
class TranslationsController extends AppController {
var $name = 'Translation';
var $components = array('Axtranslate');
var $langarr = array
('de'=>'ger','es'=>'spa','el'=>'gre','fr'=>'fre','it'=>'ita','ar'=>'ara','nl'=>'dut','zh'=>'chi');
function import() {
// Step 1: import default.pot File
$this->Translation->import('default.pot');
}
function export() {
// Step 3: export default.po file to the relevant directory
$filename= 'f' . gmdate('YmdHis');
foreach ($this->langarr as $k => $v):
$path = ROOT.DS.'app'.DS.'locale'.DS.$v;
if (!file_exists($path)) mkdir($path);
$path .= DS.'LC_MESSAGES';
if (!file_exists($path)) mkdir($path);
$file = $path.DS.$filename;
if (!file_exists($path)) touch($file);
$file = new File($path.DS.$filename);
$tmprec = $this->Translation->find('all',
array('conditions' => array('Translation.locale' => $k)));
foreach ($tmprec as $rec):
$file->write('msgid "' .$rec['Translation']
['msgid'] .'"'."\n");
$file->write('msgstr "'.$rec['Translation']
['msgstr'].'"'."\n");
endforeach;
$file->close();
if (file_exists($path.DS.'default.po'))
rename ($path.DS.'default.po',
$path.DS.'default.po.old'.gmdate('YmdHis'));
rename ($path.DS.$filename,$path.DS.'default.po');
endforeach;
}
function trans() {
// Step 2: translate to all languages defined in $langarr
$trec = $this->Translation->findAllByLocale('en');
foreach ($trec as $rec):
foreach ($this->langarr as $k => $v):
$tmprec = $this->Translation->find('all',
array('conditions' => array('Translation.locale' =>
$k,'Translation.msgid'=> $rec['Translation']['msgid'])));
if (count($tmprec) == 0) {
$this->data['Translation']['msgstr'] = $this-
>Axtranslate->translate($rec['Translation']['msgid'], 'en', $k);
$this->data['Translation']['msgid'] = $rec
['Translation']['msgid'];
$this->data['Translation']['locale'] = $k;
$this->data['Translation']['status'] = 'm';
$this->Translation->save($this->data);
}
endforeach;
endforeach;
}
}
?>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---