*
*/
-require_once 'Pman/Admin/Translations.php';
+require_once 'Pman.php';
-class Pman_Admin_Translations extends Pman_Admin_Translations
+class Pman_Admin_InterfaceTranslations extends Pman
{
-
- var $prefix = '';
+ var $prefix = '';
var $fn = '';
var $data = array();
var $original = array() ; // filename => array( orig_string > orig_string)
var $originalKeys = array() ; // md5(filename-orig_string) => filename
-
+
function getAuth()
{
}
- function get($module)
+ function get($module, $opts = Array())
{
- if (!empty($module)) {
- $this->init();
- //DB_DataObject::debugLevel(1);
- require_once 'Services/JSON.php';
- $d = DB_DataObject::factory('translations');
- $d->module = $module;
- $d->selectAdd();
- $d->selectAdd('distinct(tlang) as tlang');
- header('Content-type: text/javascript');
- $langs= $d->fetchAll('tlang');
- foreach($langs as $lang) {
- // output the translations strings file..
-
-
- $this->loadOriginalStrings($module);
-
- $data = $this->loadTranslateDB($lang,$module);
-
- $j = new Services_JSON();
- echo "_T.{$lang}= Roo.apply( _T.{$lang} || { }, " . $j->stringify($data, null, 4) . ");\n";
-
- }
- exit;
-
- }
-
- // load and parse json file containing all translations...
- if (isset($_REQUEST['id'])) {
- return $this->post();
- }
- if (empty($_REQUEST['lang']) || !preg_match('/^[A-Z_]+$/i', $_REQUEST['lang'])) {
- $this->jerr("NO LANG / INVALID LANG");
- }
-
- $enable = $this->modulesList();
-
- if (empty($_REQUEST['module']) || !in_array($_REQUEST['module'], $enable)) {
- $this->jerr("NO MODULE / INVALID MODULE");
+ if (empty($module)) {
+ $this->jerr("no module selected");
}
-
-
- $lang = $_REQUEST['lang'];
- $module = $_REQUEST['module'];
-
-
- $this->loadOriginalStrings($module); // what needs translating..
-
- $ff = $this->bootLoader;
- if (empty($ff->Pman['public_cache_dir'])) {
- $this->jerr("public_cache_dir has not been set up");
- }
-
-
-
- $translated_data = $this->loadTranslateDB($lang, $module); // the 'database!'
-
-
- // echo '<PRE>';print_R($data);exit;
- // covert data ready to send back..
-
- $ret = array();
- foreach($this->original as $k=>$ar) {
- foreach($ar as $tr=>$trv) {
- // $hint = isset($hints[$tr]) ? $hints[$tr] : '';
- $key = md5($k.'-'.$tr);
- $ret[] = array(
- 'id' => $lang.'/'.$key,
- 'msum' => $key,
- 'colname' => $k,
- 'origtxt' => $tr,
- 'txt' => isset($translated_data[$key]) ? $translated_data[$key] : '',
- // 'suggest' => $hint
- );
+ $this->init();
+ //DB_DataObject::debugLevel(1);
+ require_once 'Services/JSON.php';
+ $d = DB_DataObject::factory('translations');
+ $d->module = $module;
+ $d->selectAdd();
+ $d->selectAdd('distinct(tlang) as tlang');
+ header('Content-type: text/javascript');
+ $langs= $d->fetchAll('tlang');
+ foreach($langs as $lang) {
+ // output the translations strings file..
+
- }
+ $this->loadOriginalStrings($module);
+
+ $data = $this->loadTranslateDB($lang,$module);
+
+ $j = new Services_JSON();
+ echo "_T = _T || {} ; _T.{$lang}= Roo.apply( _T.{$lang} || { }, " . $j->stringify($data, null, 4) . ");\n";
+
}
-
-
- $this->jdata($ret);
-
-
exit;
-
+
}
- function post()
+ function post($v)
{
-
-
-
- if (empty($_REQUEST['module']) || !in_array($_REQUEST['module'], $this->modulesList())) {
- $this->jerr("NO MODULE / INVALID MODULE");
- }
-
- //id zh_HK/54e1d44609e3abed11f6e1eb6ae54988
- //txt é \85ç\9b®
- list($lang,$id) = explode('/', $_REQUEST['id']);
-
- $this->loadOriginalStrings($_REQUEST['module']);
-
- $data = $this->loadTranslateDB($lang,$_REQUEST['module']);
-
- $data[$id] = $_REQUEST['txt'];
-
- if (!isset($this->originalKeys[$id])) {
-
-
- $this->jerr("invalid key ?");
- }
-
- $this->saveTranslateDB($lang,$_REQUEST['module'],$this->originalKeys[$id], $id, $_REQUEST['txt']);
-
-
-
- $this->writeTransMod($lang,$_REQUEST['module'], $data);
- // write merged file..
- //$this->prefix = '_T["'.$lang .'"]=';
- //file_put_contents($this->fn, $this->prefix. $j->encode($this->data).';');
- $this->jok("OK");
+ $this->jerr("invalid url");
+
}
- /**
+ /**
* load strings that need translating..
*/
// since this can handle errors better.!!?
$info = $this->moduleJavascriptFilesInfo($module);
//print_r($info);
- $tfile =$info->basedir . '/'. $info->translation_data;
+
+
+
+ $this->original = array();
+ $tfile = $info->basedir . '/'. $info->translation_data;
//var_dump($tfile);
- if (empty($tfile) || !file_exists($tfile)) {
- return array();
+ //if (empty($tfile) || !file_exists($tfile)) {
+
+ foreach($info->filesmtime as $f =>$mt) {
+ $bjs = preg_replace('/\.js$/','.bjs', $f);
+ if (!file_exists($bjs)) {
+ continue;
+ }
+ $jd = json_decode(file_get_contents($bjs));
+ if (empty($jd->strings)) {
+ continue;
+ }
+ $this->original[str_replace('.bjs', '', basename($bjs)) ] = array_flip((array)$jd->strings);
}
+
+ file_put_contents($tfile, json_encode($this->original));
+
+ //}
- require_once 'Services/JSON.php';
- $j = new Services_JSON();
- $this->original = (array) $j->decode('{'. file_get_contents($tfile).'}');
+
+ //print_R($this->original);exit;
+
+
+ $this->original = (array) json_decode( file_get_contents($tfile) );
ksort($this->original);
$this->originalKeys = array();
}
-
-
-
-
/***
*
* loadTranslateDB -
}
- function saveTranslateDB($lang, $module, $tfile, $tkey, $tval)
- {
- $d = DB_DataObject::factory('translations');
- $d->module = $module;
- $d->tlang = $lang;
- $d->tfile = $tfile;
- $d->tkey = $tkey;
- if ($d->find(true)) {
- $d->tval = $tval;
- $d->update();
- }
- $d->tval = $tval;
- $d->insert();
-
- }
-
-
-
-
- function getTransFilename($lang, $module)
- {
-
- $ff = HTML_FlexyFramework::get();
- $fn = $ff->rootDir .'/_translations_/'. $lang . '/'. $module.'.json';
- if (!file_exists(dirname($fn))) {
-
- /// create the direct
- $oldumask = umask(0);
- mkdir(dirname($fn), 0770, true);
- umask($oldumask);
- clearstatcache();
- if (!file_exists(dirname($fn))) {
- $this->jerr("_translations_ directory does not exist in Pman folder - it needs to be editable");
- }
-
- }
- return $fn;
- }
-
-
- /**
- * Writes a file MODULE.js inside of _translations_
- *
- * this should contain all contents from all the language directroris for this
- * module
- *
- */
-
- function writeTransMod($lang, $module, $data)
- {
- //print_R($data);
-
-
- $fn = $this->getTransFilename($lang, $module);
- require_once 'Services/JSON.php';
- $j = new Services_JSON();
-
- file_put_contents($fn, $j->stringify($data, null, 4));
-
- $ff = HTML_FlexyFramework::get();
- $base = $ff->rootDir.'/_translations_' ;
- $out = '';
- foreach(scandir($base) as $l) {
-
- if (!strlen($l) || $l[0] == '.' || !is_dir("$base/$l") || !file_exists("$base/$l/$module.json")) {
- continue;
- }
- // decode as our temp files contain spaces..
- $jdata = json_decode(file_get_contents("$base/$l/$module.json") );
- $out .= "_T.$l= Roo.apply( _T.$l || { }, " . json_encode($jdata) . ");\n";
- }
- //var_dump($out);
- if (strlen($out)) {
- file_put_contents("$base/$module.js", $out);
- }
- //$this->writeTrans($lang);
- }
-
-
}
\ No newline at end of file