';print_r($this->translationMap);
foreach($this->translationMap as $page=>$map) {
if (isset($map[$string])) {
$ids[] = $map[$string];
}
}
//echo '';print_r(array($string,$lang,$ids,$this->translations[$lang]));
//exit;
if (!$ids) {
return array();
}
$ret = array();
foreach($ids as $id) {
if (isset($this->translations[$lang][$id])) {
$ret[] = $this->translations[$lang][$id];
}
}
// echo '';print_r($ret);
return $ret;
}
function getTranslation($page,$word,$lang)
{
if (!isset($this->translationMap[$page][$word])) {
//echo "No string id for $page : $word\n";
return false;
}
if (!isset($this->translations[$lang][$this->translationMap[$page][$word]])) {
return false;
}
return $this->translations[$lang][$this->translationMap[$page][$word]];
}
/**
* compile all the templates in a specified folder.
*
*
* @param string subdirectory of templateDir or empty
* @return none
* @access public
*/
function compileAll($d='')
{
set_time_limit(0); // this could take quite a while!!!
$words = array();
$dname = $d ? $this->options['templateDir'] .'/'.$d : $this->options['templateDir'];
//echo "Open $dname
";
$dh = opendir( $dname);
require_once 'HTML/Template/Flexy.php';
$o = $this->options;
$o['fatalError'] = PEAR_ERROR_RETURN;
$o['locale'] = 'en';
while (($name = readdir($dh)) !== false) {
$fname = $d ? $d .'/'. $name : $name;
if ($name{0} == '.') {
continue;
}
if (is_dir($this->options['templateDir'] . '/'. $fname)) {
$this->compileAll($fname);
continue;
}
if (!preg_match('/\.html$/',$name)) {
continue;
}
$oo = $o;// $oo['debug'] = 1;
$x = new HTML_Template_Flexy( $oo );
$r = $x->compile($fname);
//printf(" %0.3fs : $fname
", $time);
if (is_object($r) && is_a($r,'PEAR_Error')) {
echo "compile failed on $fname
";
echo $r->toString();
continue;
}
$this->words[$fname] = file_exists($x->getTextStringsFile) ?
unserialize(file_get_contents($x->getTextStringsFile)) :
array();
}
//echo '';print_R($words);exit;
ksort($this->words);
}
/**
* delete all the compiled templates in a specified language
*
*
* @param string language
* @param string subdirectory of templateDir or empty
* @return none
* @access public
*/
function clearTemplateCache($lang='en',$d = '') {
$dname = $d ? $this->options['templateDir'] .'/'.$d : $this->options['templateDir'];
$dh = opendir($dname);
while (($name = readdir($dh)) !== false) {
$fname = $d ? $d .'/'. $name : $name;
if ($name{0} == '.') {
continue;
}
if (is_dir($this->options['templateDir'] . '/'. $fname)) {
$this->clearTemplateCache($lang,$fname);
continue;
}
if (!preg_match('/\.html$/',$name)) {
continue;
}
$file = "{$this->options['compileDir']}/{$fname}.{$lang}.php";
if (file_exists($file)) {
// echo "DELETE $file?";
unlink($file);
}
}
clearstatcache();
}
/**
* output the default template with the editing facilities.
*
* @return none
* @access public
*/
function outputDefaultTemplate() {
$o = array(
'compileDir' => ini_get('session.save_path') . '/HTML_Template_Flexy_Translate',
'templateDir' => dirname(__FILE__).'/templates'
);
$x = new HTML_Template_Flexy( $o );
$x->compile('translator.html');
$x->outputObject($this);
}
}