From fde10d5d477dbfda94425a296bdf5e3b3ab32764 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Sun, 23 Jan 2011 18:18:32 +0100 Subject: [PATCH] string.php translation utility --- util/string_translator.php | 180 +++++++++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 util/string_translator.php diff --git a/util/string_translator.php b/util/string_translator.php new file mode 100644 index 0000000000..4d24f7a6f6 --- /dev/null +++ b/util/string_translator.php @@ -0,0 +1,180 @@ + + + + + + +read())) { + if (is_file($d->path."/".$entry."/strings.php")){ + $LANGS[] = $entry; + } + +} +$d->close(); + + +class A{ + var $strings = Array(); +} + +function loadstrings($lang = NULL){ + global $FRIENDIKA_PATH; + if (is_null($lang)) { + $path = $FRIENDIKA_PATH."/util/strings.php"; + } else { + $path = $FRIENDIKA_PATH."/view/$lang/strings.php"; + } + $a = new A(); + include_once($path); + return $a->strings; +} + + +function savestrings($lang, $strings){ + global $FRIENDIKA_PATH; + $path = $FRIENDIKA_PATH."/view/$lang/strings.php"; + $f = fopen($path,"w"); + fwrite($f, "<"); fwrite($f, "?php\n"); + foreach($strings as $k=>$v){ + $k=str_replace("'","\'", $k); + $k=str_replace("\\\\'","\'", $k); + $k=str_replace("\n","\\n", $k); + $k=str_replace("\r","\\r", $k); + $v=str_replace("'","\'", $v); + $v=str_replace("\\\\'","\'", $v); + $v=str_replace("\n","\\n", $v); + $v=str_replace("\r","\\r", $v); + + fwrite( $f, '$a->strings[\''.$k.'\'] = \''. $v .'\';'."\n" ); + #echo '$a->strings[\''.$k.'\'] = \''. $v .'\''."\n" ; + } + fwrite($f, "?"); fwrite($f, ">\n"); + fclose($f); +} + + + +function hexstr($hexstr) { + $hexstr = str_replace(' ', '', $hexstr); + $hexstr = str_replace('\x', '', $hexstr); + $retstr = pack('H*', $hexstr); + return $retstr; +} + +function strhex($string) { + $hexstr = unpack('H*', $string); + return array_shift($hexstr); +} + + +echo "

Translator

"; +echo "

Utility to translate string.php file."; +echo " Need write permission to language file you want to modify

"; +echo "

Installed languages:"; +echo "

"; + + +$strings['en'] = loadstrings(); + +if (isset($_GET['lang'])){ + + $lang = $_GET['lang']; + $strings[$lang] = loadstrings($lang); + + $n1 = count($strings['en']); + $n2 = count($strings[$lang]); + + echo "
";
+	echo "Tranlsate en to $lang
"; + //echo "Translated $n2 over $n1 strings
"; + echo "

"; + + + + if (isset($_POST['save'])){ + echo "saving..."; + foreach ($_POST as $k=>$v){ + if ($k!="save" && $k!="from"){ + $k=hexstr($k); + $strings[$lang][$k] = $v; + } + } + savestrings($lang, $strings[$lang]); + echo "ok.
"; + } + + + + + + if (!isset($_POST['from'])){ + $from=0; + } else { + $from = $_POST['from']; + if ($_POST['save']=="Next") + $from += 10; + if ($_POST['save']=="Prev") + $from -= 10; + } + $count = count($strings['en']); + $len = 10; + if ($from+$len>$count) $len=$count-$from; + $thestrings = array_slice($strings['en'], $from, $len, true); + + + + echo "
"; + + if ($from>0) + echo ""; + echo ""; + if ($from+$len<$count) + echo ""; + + foreach($thestrings as $k=>$v){ + $id = strhex($k); + $translation = $strings[$lang][$k]; + + $v=str_replace("\n","\\n", $v); + $v=str_replace("\r","\\r", $v); + $translation=str_replace("\n","\\n", $translation); + $translation=str_replace("\r","\\r", $translation); + + $istranslate = $translation != '' ? 'yes':'no'; + echo "
"; + echo "
"; + echo "
"; + echo "
"; + } + + + echo ""; + + if ($from>0) + echo ""; + echo ""; + if ($from+$len<$count) + echo ""; + + echo "
"; + + +} +?> + + +