2011-03-18 10:03:15 +00:00
|
|
|
<?php
|
|
|
|
|
2018-07-19 22:22:04 +00:00
|
|
|
if(! class_exists('App')) {
|
|
|
|
class App {
|
2018-07-20 14:40:35 +00:00
|
|
|
static public $rtl;
|
|
|
|
static public $strings = Array();
|
2018-07-19 22:22:04 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-18 10:03:15 +00:00
|
|
|
|
2018-07-28 15:36:48 +00:00
|
|
|
if ($argc!=2) {
|
2019-06-14 05:39:40 +00:00
|
|
|
print "Usage: ".$argv[0]." <strings.php>\n\n";
|
2018-07-28 15:36:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$phpfile = $argv[1];
|
2019-06-14 05:39:40 +00:00
|
|
|
$pofile = dirname($phpfile)."/messages.po";
|
2018-07-28 15:36:48 +00:00
|
|
|
|
|
|
|
if (!file_exists($phpfile)){
|
|
|
|
print "Unable to find '$phpfile'\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
include_once($phpfile);
|
2011-03-18 10:03:15 +00:00
|
|
|
|
2018-07-28 15:36:48 +00:00
|
|
|
print "Out to '$pofile'\n";
|
2011-03-18 10:03:15 +00:00
|
|
|
|
2018-07-28 15:36:48 +00:00
|
|
|
$out = "";
|
|
|
|
$infile = file($pofile);
|
2018-07-29 10:05:53 +00:00
|
|
|
$k = "";
|
|
|
|
$c = "";
|
2018-07-28 15:36:48 +00:00
|
|
|
$ink = False;
|
|
|
|
foreach ($infile as $l) {
|
2011-03-18 10:03:15 +00:00
|
|
|
|
2018-07-29 12:20:01 +00:00
|
|
|
$l = trim($l, " ");
|
2018-07-28 15:36:48 +00:00
|
|
|
if (!preg_match("/^msgstr\[[1-9]/",$l)) {
|
|
|
|
if ($k!="" && (substr($l,0,7)=="msgstr " || substr($l,0,8)=="msgstr[0")){
|
|
|
|
$ink = False;
|
2018-09-13 19:28:15 +00:00
|
|
|
$k = stripcslashes($k);
|
2018-07-28 15:36:48 +00:00
|
|
|
$v = "";
|
|
|
|
if (isset(App::$strings[$k])) {
|
|
|
|
$v = App::$strings[$k];
|
2018-07-29 00:11:27 +00:00
|
|
|
} else {
|
|
|
|
$k = "__ctx:".$c."__ ".$k;
|
2018-07-29 10:05:53 +00:00
|
|
|
if (isset(App::$strings[$k])) {
|
2018-07-29 00:11:27 +00:00
|
|
|
$v = App::$strings[$k];
|
2018-07-29 10:05:53 +00:00
|
|
|
$c = "";
|
2018-07-29 14:26:33 +00:00
|
|
|
};
|
2018-07-29 00:11:27 +00:00
|
|
|
}
|
|
|
|
if (!empty($v)) {
|
2018-07-28 15:36:48 +00:00
|
|
|
if (is_array($v)) {
|
|
|
|
$l = "";
|
|
|
|
$n = 0;
|
|
|
|
foreach ($v as &$value) {
|
2018-07-29 14:26:33 +00:00
|
|
|
$l .= "msgstr[".$n."] \"".addcslashes($value,"\"\n")."\"\n";
|
2018-07-28 15:36:48 +00:00
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
} else {
|
2018-07-29 14:26:33 +00:00
|
|
|
$l = "msgstr \"".addcslashes($v,"\"\n")."\"\n";
|
2018-07-28 15:36:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (substr($l,0,6)=="msgid_" || substr($l,0,7)=="msgstr[") $ink = False;
|
|
|
|
|
|
|
|
if ($ink) {
|
2018-07-29 14:26:33 +00:00
|
|
|
preg_match('/^"(.*)"$/',$l,$m);
|
|
|
|
$k .= $m[1];
|
2018-07-28 15:36:48 +00:00
|
|
|
}
|
|
|
|
|
2018-07-29 00:11:27 +00:00
|
|
|
if (substr($l,0,6)=="msgid ") {
|
2018-07-29 12:20:01 +00:00
|
|
|
preg_match('/^msgid "(.*)"$/',$l,$m);
|
2018-07-29 00:11:27 +00:00
|
|
|
$k = $m[1];
|
2018-07-28 15:36:48 +00:00
|
|
|
$ink = True;
|
|
|
|
}
|
|
|
|
|
2018-07-29 00:11:27 +00:00
|
|
|
if (substr($l,0,8)=="msgctxt ") {
|
2018-07-29 12:20:01 +00:00
|
|
|
preg_match('/^msgctxt "(.*)"$/',$l,$m);
|
2018-07-29 00:11:27 +00:00
|
|
|
$c = $m[1];
|
|
|
|
}
|
|
|
|
|
2018-07-28 15:36:48 +00:00
|
|
|
$out .= $l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file_put_contents($pofile, $out);
|
|
|
|
?>
|