template_dir = './'; $t->compile_dir = '../tmp'; $localeSlaveMessages = $this->_getLocaleArray($this->_localeSlave); $localeMasterMessages = $this->_getLocaleArray($this->_localeMaster); $localeSlaveMessages = (!$localeSlaveMessages) ? array() : $localeSlaveMessages; $localeSlaveMessages = $this->_cleanArray($localeSlaveMessages); $localeMasterMessages = $this->_cleanArray($localeMasterMessages); $t->assign('localemasterstrings', $localeMasterMessages); $t->assign('localeslavestrings', $this->_mergeLocales($localeMasterMessages,$localeSlaveMessages) ); $t->display('translator.tpl'); } function write($newStrings) { $mastertpl = file($this->_localeMaster); @unlink($this->_localeSlave); touch($this->_localeSlave); $handle = fopen($this->_localeSlave, "r+b"); foreach($mastertpl as $line) { $match = false; foreach($newStrings as $key => $string) { $test = '$messages[\'' . $key . "']"; if (stristr($line, $test) && ($string != '+array+')) { $newline = '$messages[\'' . $key . "'] = '" . $string . "';\n"; fwrite($handle, $newline); $match = true; break; } } if ($match === false) { fwrite($handle, $line); } } fclose($handle); return true; } function _mergeLocales($master = array(), $slave = array()) { // override all translated strings and leave the rest in the master language $mergedLocale = array(); $mergedLocale = array_merge($master, $slave); /* foreach($master as $stringId => $string ) { if (array_key_exists($stringId, $slave)) { $mergedLocale["$stringId"] = $slave["$stringId"]; } else { if (is_array($string)) { $mergedLocale["$stringId"] = $master["+array+"]; } else { $mergedLocale["$stringId"] = $master["$stringId"]; } } } */ return $mergedLocale; /*$i = 0; $max = count($string); for ($i = 0; $i < $max; $i++ ) { }*/ } function _cleanArray($messages) { foreach($messages as $msgId => $msg) { if (is_array($msg)) { $messages["$msgId"] = '+array+'; } if (in_array($msgId, $this->_blacklist) ) { unset($messages["$msgId"]); } } //var_dump($messages); return $messages; } function _getLocaleArray($path = '') { if( is_readable("$path") ) { include_once("$path"); if(!isset($messages)) { $messages = array(); } return $messages; } else { return false; } } function _getLocaleFile($path = '') { if( is_readable("$path") ) { return file("$path"); } else { return false; } } /* function setAdminSlave ($path) { $this->_adminSlave = $path; return true; } */ function setLocaleSlave ($path) { $this->_localeSlave = $path; return true; } /* function setAdminMaster ($path) { $this->_adminMaster = $path; return true; } */ function setLocaleMaster ($path) { $this->_localeMaster = $path; return true; } } ### ?>