1
0
Fork 0

Fix to po2php on multiline msgstr

This commit is contained in:
Fabio Comuni 2011-03-18 11:25:22 +01:00
parent 8ef6077d4d
commit 7e4f22a0b6

View file

@ -22,10 +22,13 @@ function po2php_run($argv, $argc) {
$infile = file($pofile); $infile = file($pofile);
$k=""; $k="";
$v="";
$arr = False; $arr = False;
$ink = False; $ink = False;
$inv = False;
foreach ($infile as $l) { foreach ($infile as $l) {
$len = strlen($l); $len = strlen($l);
if ($l[0]=="#") $l="";
if (substr($l,0,15)=='"Plural-Forms: '){ if (substr($l,0,15)=='"Plural-Forms: '){
$match=Array(); $match=Array();
preg_match("|nplurals=([0-9]*); plural=(.*);|", $l, $match); preg_match("|nplurals=([0-9]*); plural=(.*);|", $l, $match);
@ -40,11 +43,15 @@ function po2php_run($argv, $argc) {
if ($k!="" && substr($l,0,7)=="msgstr "){ if ($k!="" && substr($l,0,7)=="msgstr "){
if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; } if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }
$v = substr($l,7,$len-8); if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
$out .= $v;
$v = substr($l,8,$len-10);
$inv = True;
//$out .= $v;
} }
if ($k!="" && substr($l,0,7)=="msgstr["){ if ($k!="" && substr($l,0,7)=="msgstr["){
if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; } if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }
if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
if (!$arr) { if (!$arr) {
$arr=True; $arr=True;
@ -57,12 +64,14 @@ function po2php_run($argv, $argc) {
if (substr($l,0,6)=="msgid_") { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }; if (substr($l,0,6)=="msgid_") { $ink = False; $out .= '$a->strings["'.$k.'"] = '; };
if ($ink) { if ($ink) {
$k .= trim($l,"\" \r\n"); $k .= trim($l,"\"\r\n");
//$out .= '$a->strings['.$k.'] = '; //$out .= '$a->strings['.$k.'] = ';
} }
if (substr($l,0,6)=="msgid "){ if (substr($l,0,6)=="msgid "){
if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
if ($k!="") $out .= $arr?");\n":";\n"; if ($k!="") $out .= $arr?");\n":";\n";
$arr=False; $arr=False;
$k = str_replace("msgid ","",$l); $k = str_replace("msgid ","",$l);
@ -74,9 +83,15 @@ function po2php_run($argv, $argc) {
$ink = True; $ink = True;
} }
if ($inv && substr($l,0,6)!="msgstr") {
$v .= trim($l,"\"\r\n");
//$out .= '$a->strings['.$k.'] = ';
}
} }
if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
if ($k!="") $out .= $arr?");\n":";\n"; if ($k!="") $out .= $arr?");\n":";\n";
file_put_contents($outfile, $out); file_put_contents($outfile, $out);