4 function po2php_run($argv, $argc) {
7 print "Usage: ".$argv[0]." <file.po>\n\n";
12 $outfile = dirname($pofile)."/strings.php";
14 if (!file_exists($pofile)){
15 print "Unable to find '$pofile'\n";
19 print "Out to '$outfile'\n";
23 $infile = file($pofile);
29 foreach ($infile as $l) {
31 if ($l[0]=="#") $l="";
32 if (substr($l,0,15)=='"Plural-Forms: '){
34 preg_match("|nplurals=([0-9]*); plural=(.*);|", $l, $match);
35 $cond = str_replace('n','$n',$match[2]);
36 $out .= 'function string_plural_select($n){'."\n";
37 $out .= ' return '.$cond.';'."\n";
44 if ($k!="" && substr($l,0,7)=="msgstr "){
45 if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }
46 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
48 $v = substr($l,8,$len-10);
52 if ($k!="" && substr($l,0,7)=="msgstr["){
53 if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }
54 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
61 preg_match("|\[([0-9]*)\] (.*)|", $l, $match);
62 $out .= "\t". $match[1]." => ". $match[2] .",\n";
65 if (substr($l,0,6)=="msgid_") { $ink = False; $out .= '$a->strings["'.$k.'"] = '; };
69 $k .= trim($l,"\"\r\n");
70 //$out .= '$a->strings['.$k.'] = ';
73 if (substr($l,0,6)=="msgid "){
74 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
75 if ($k!="") $out .= $arr?");\n":";\n";
77 $k = str_replace("msgid ","",$l);
79 $k = trim($k,"\"\r\n");
86 if ($inv && substr($l,0,6)!="msgstr") {
87 $v .= trim($l,"\"\r\n");
88 //$out .= '$a->strings['.$k.'] = ';
94 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
95 if ($k!="") $out .= $arr?");\n":";\n";
97 file_put_contents($outfile, $out);
101 if (array_search(__file__,get_included_files())===0){
102 po2php_run($argv,$argc);