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