1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style>
textarea { width: 100% }
.no { background: #ffdddd; }
</style>
</head>
<body>
<?php
$FRIENDIKA_PATH = dirname(dirname(__FILE__));
/* find languages */
$LANGS=array();
$d = dir($FRIENDIKA_PATH."/view");
while (false !== ($entry = $d->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 "<h1>Translator</h1>";
echo "<p>Utility to translate <code>string.php</code> file.";
echo " Need write permission to language file you want to modify</p>";
echo "<p>Installed languages:";
echo "<ul>";
foreach($LANGS as $l){
echo "<li><a href='?lang=$l'>$l</a></li>";
}
echo "</ul></p>";
$strings['en'] = loadstrings();
if (isset($_GET['lang'])){
$lang = $_GET['lang'];
$strings[$lang] = loadstrings($lang);
$n1 = count($strings['en']);
$n2 = count($strings[$lang]);
echo "<pre>";
echo "Tranlsate en to $lang<br>";
//echo "Translated $n2 over $n1 strings<br>";
echo "</pre><hr/>";
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.<br>";
}
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 "<form method='POST'>";
if ($from>0)
echo "<input type='submit' name='save' id='save' value='Prev'/>";
echo "<input type='submit' name='reload' id='reload' value='Reload'/>";
if ($from+$len<$count)
echo "<input type='submit' name='save' id='save' value='Next'/>";
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 "<dl class='$istranslate'>";
echo "<dt><label for='$id'>".htmlspecialchars($v)."</label></dt>";
echo "<dd><textarea id='$id' name='$id'>$translation</textarea></dd>";
echo "</dl>";
}
echo "<input type='hidden' name='from' value='$from'/>";
if ($from>0)
echo "<input type='submit' name='save' id='save' value='Prev'/>";
echo "<input type='submit' name='reload' id='reload' value='Reload'/>";
if ($from+$len<$count)
echo "<input type='submit' name='save' id='save' value='Next'/>";
echo "</form>";
}
?>
</body>
</html>
|