From fd4256a13f879089351aaf36d557de4b7d3ea99e Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Fri, 18 Mar 2011 11:03:15 +0100 Subject: [PATCH] php2po script --- util/php2po.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 util/php2po.php diff --git a/util/php2po.php b/util/php2po.php new file mode 100644 index 000000000..d3ce0a5af --- /dev/null +++ b/util/php2po.php @@ -0,0 +1,71 @@ +\n\n"; + return; + } + + $phpfile = $argv[1]; + $pofile = dirname($phpfile)."/messages.po"; + + if (!file_exists($phpfile)){ + print "Unable to find '$phpfile'\n"; + return; + } + + include_once($phpfile); + + print "Out to '$pofile'\n"; + + $out = ""; + $infile = file($pofile); + $k=""; + $ink = False; + foreach ($infile as $l) { + + if ($k!="" && substr($l,0,7)=="msgstr "){ + $ink = False; + $v = '""'; + //echo "DBG: k:'$k'\n"; + if (isset($a->strings[$k])) { + $v= '"'.$a->strings[$k].'"'; + //echo "DBG\n"; + //var_dump($k, $v, $a->strings[$k], $v); + //echo "/DBG\n"; + + } + //echo "DBG: v:'$v'\n"; + $l = "msgstr ".$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 (substr($l,0,6)=="msgid "){ + $arr=False; + $k = str_replace("msgid ","",$l); + if ($k != '""' ) { + $k = trim($k,"\"\r\n"); + $k = str_replace('\"','"',$k); + } else { + $k = ""; + } + $ink = True; + } + + $out .= $l; + } + //echo $out; + file_put_contents($pofile, $out); +?> \ No newline at end of file