Plural form strings export added

This commit is contained in:
Max Kostikov 2018-07-28 17:36:48 +02:00
parent 27329e39e4
commit e27e0ca198

View File

@ -7,65 +7,68 @@
} }
} }
if ($argc!=2) { if ($argc!=2) {
print "Usage: ".$argv[0]." <hstrings.php>\n\n"; print "Usage: ".$argv[0]." <hstrings.php>\n\n";
return; return;
} }
$phpfile = $argv[1];
$pofile = dirname($phpfile)."/hmessages.po";
if (!file_exists($phpfile)){ $phpfile = $argv[1];
print "Unable to find '$phpfile'\n"; $pofile = dirname($phpfile)."/hmessages.po";
return;
}
include_once($phpfile); if (!file_exists($phpfile)){
print "Unable to find '$phpfile'\n";
return;
}
print "Out to '$pofile'\n"; include_once($phpfile);
$out = ""; print "Out to '$pofile'\n";
$infile = file($pofile);
$k=""; $out = "";
$ink = False; $infile = file($pofile);
foreach ($infile as $l) { $k="";
$ink = False;
if ($k!="" && substr($l,0,7)=="msgstr "){ foreach ($infile as $l) {
$ink = False;
$v = ''; if (!preg_match("/^msgstr\[[1-9]/",$l)) {
//echo "DBG: k:'$k'\n"; if ($k!="" && (substr($l,0,7)=="msgstr " || substr($l,0,8)=="msgstr[0")){
if (isset(App::$strings[$k])) { $ink = False;
$v= App::$strings[$k]; $v = "";
//echo "DBG\n"; if (isset(App::$strings[$k])) {
//var_dump($k, $v, App::$strings[$k], $v); $v = App::$strings[$k];
//echo "/DBG\n"; if (is_array($v)) {
$l = "";
} $n = 0;
//echo "DBG: v:'$v'\n"; foreach ($v as &$value) {
$l = "msgstr \"".str_replace('"','\"',$v)."\"\n"; $l .= "msgstr[".$n."] \"".str_replace('"','\"',$value)."\"\n";
} $n++;
}
if (substr($l,0,6)=="msgid_" || substr($l,0,7)=="msgstr[" )$ink = False;; } else {
$l = "msgstr \"".str_replace('"','\"',$v)."\"\n";
if ($ink) { }
$k .= trim($l,"\"\r\n"); }
$k = str_replace('\"','"',$k); }
}
if (substr($l,0,6)=="msgid_" || substr($l,0,7)=="msgstr[") $ink = False;
if (substr($l,0,6)=="msgid "){
$arr=False; if ($ink) {
$k = str_replace("msgid ","",$l); $k .= trim($l,"\"\r\n");
if ($k != '""' ) { $k = str_replace('\"','"',$k);
$k = trim($k,"\"\r\n"); }
$k = str_replace('\"','"',$k);
} else { if (substr($l,0,6)=="msgid "){
$k = ""; $k = str_replace("msgid ","",$l);
} if ($k != '""' ) {
$ink = True; $k = trim($k,"\"\r\n");
} $k = str_replace('\"','"',$k);
} else {
$out .= $l; $k = "";
} }
//echo $out; $ink = True;
file_put_contents($pofile, $out); }
?>
$out .= $l;
}
}
file_put_contents($pofile, $out);
?>