4 function po2php_run($argv, $argc) {
7 print "Usage: ".$argv[0]." <file.po>\n\n";
12 $outfile = dirname($pofile)."/strings.php";
14 if(strstr($outfile,'util'))
17 $lang = str_replace('-','_',basename(dirname($pofile)));
21 if (!file_exists($pofile)){
22 print "Unable to find '$pofile'\n";
26 print "Out to '$outfile'\n";
30 $infile = file($pofile);
36 $escape_s_exp = '|[^\\\\]\$[a-z]|';
37 function escape_s($match){
38 return str_replace('$','\$',$match[0]);
40 foreach ($infile as $l) {
42 if ($l[0]=="#") $l="";
43 if (substr($l,0,15)=='"Plural-Forms: '){
45 preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match);
46 $cond = str_replace('n','$n',$match[2]);
47 $out .= 'function string_plural_select_' . $lang . '($n){'."\n";
48 $out .= ' return '.$cond.';'."\n";
55 if ($k!="" && substr($l,0,7)=="msgstr "){
56 if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }
57 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
59 $v = substr($l,8,$len-10);
60 $v = preg_replace_callback($escape_s_exp,'escape_s',$v);
64 if ($k!="" && substr($l,0,7)=="msgstr["){
65 if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }
66 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
73 preg_match("|\[([0-9]*)\] (.*)|", $l, $match);
75 preg_replace_callback($escape_s_exp,'escape_s',$match[1])
77 .preg_replace_callback($escape_s_exp,'escape_s',$match[2]) .",\n";
80 if (substr($l,0,6)=="msgid_") { $ink = False; $out .= '$a->strings["'.$k.'"] = '; };
84 $k .= trim($l,"\"\r\n");
85 $k = preg_replace_callback($escape_s_exp,'escape_s',$k);
86 //$out .= '$a->strings['.$k.'] = ';
89 if (substr($l,0,6)=="msgid "){
90 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
91 if ($k!="") $out .= $arr?");\n":";\n";
93 $k = str_replace("msgid ","",$l);
95 $k = trim($k,"\"\r\n");
100 $k = preg_replace_callback($escape_s_exp,'escape_s',$k);
104 if ($inv && substr($l,0,6)!="msgstr") {
105 $v .= trim($l,"\"\r\n");
106 $v = preg_replace_callback($escape_s_exp,'escape_s',$v);
107 //$out .= '$a->strings['.$k.'] = ';
113 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
114 if ($k!="") $out .= $arr?");\n":";\n";
116 file_put_contents($outfile, $out);
120 if (array_search(__file__,get_included_files())===0){
121 po2php_run($argv,$argc);