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 $escape_s_exp = '|[^\\\\]\$[a-z]|';
30 function escape_s($match){
31 return str_replace('$','\$',$match[0]);
33 foreach ($infile as $l) {
35 if ($l[0]=="#") $l="";
36 if (substr($l,0,15)=='"Plural-Forms: '){
38 preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match);
39 $cond = str_replace('n','$n',$match[2]);
40 $out .= 'function string_plural_select($n){'."\n";
41 $out .= ' return '.$cond.';'."\n";
48 if ($k!="" && substr($l,0,7)=="msgstr "){
49 if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }
50 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
52 $v = substr($l,8,$len-10);
53 $v = preg_replace_callback($escape_s_exp,'escape_s',$v);
57 if ($k!="" && substr($l,0,7)=="msgstr["){
58 if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }
59 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
66 preg_match("|\[([0-9]*)\] (.*)|", $l, $match);
68 preg_replace_callback($escape_s_exp,'escape_s',$match[1])
70 .preg_replace_callback($escape_s_exp,'escape_s',$match[2]) .",\n";
73 if (substr($l,0,6)=="msgid_") { $ink = False; $out .= '$a->strings["'.$k.'"] = '; };
77 $k .= trim($l,"\"\r\n");
78 $k = preg_replace_callback($escape_s_exp,'escape_s',$k);
79 //$out .= '$a->strings['.$k.'] = ';
82 if (substr($l,0,6)=="msgid "){
83 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
84 if ($k!="") $out .= $arr?");\n":";\n";
86 $k = str_replace("msgid ","",$l);
88 $k = trim($k,"\"\r\n");
93 $k = preg_replace_callback($escape_s_exp,'escape_s',$k);
97 if ($inv && substr($l,0,6)!="msgstr") {
98 $v .= trim($l,"\"\r\n");
99 $v = preg_replace_callback($escape_s_exp,'escape_s',$v);
100 //$out .= '$a->strings['.$k.'] = ';
106 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
107 if ($k!="") $out .= $arr?");\n":";\n";
109 file_put_contents($outfile, $out);
113 if (array_search(__file__,get_included_files())===0){
114 po2php_run($argv,$argc);