streams/util/php2po.php

71 lines
1.2 KiB
PHP
Raw Normal View History

2011-03-18 10:03:15 +00:00
<?php
if(! class_exists('App')) {
class TmpA {
public $strings = Array();
}
$a = new TmpA();
}
if ($argc!=2) {
print "Usage: ".$argv[0]." <hstrings.php>\n\n";
2011-03-18 10:03:15 +00:00
return;
}
$phpfile = $argv[1];
$pofile = dirname($phpfile)."/hmessages.po";
2011-03-18 10:03:15 +00:00
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";
2016-03-31 23:06:03 +00:00
if (isset(App::$strings[$k])) {
$v= '"'.App::$strings[$k].'"';
2011-03-18 10:03:15 +00:00
//echo "DBG\n";
2016-03-31 23:06:03 +00:00
//var_dump($k, $v, App::$strings[$k], $v);
2011-03-18 10:03:15 +00:00
//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);
?>