2 define("DQ_ESCAPE", "__DQ__");
5 function po2php_run(&$argv, &$argc) {
8 print "Usage: ".$argv[0]." <file.po>\n\n";
13 $outfile = dirname($pofile)."/strings.php";
15 if(strstr($outfile,'util'))
18 $lang = str_replace('-','_',basename(dirname($pofile)));
22 if (!file_exists($pofile)){
23 print "Unable to find '$pofile'\n";
27 print "Out to '$outfile'\n";
31 $infile = file($pofile);
37 $escape_s_exp = '|[^\\\\]\$[a-z]|';
38 function escape_s($match){
39 return str_replace('$','\$',$match[0]);
41 foreach ($infile as $l) {
42 $l = str_replace('\"', DQ_ESCAPE, $l);
44 if ($l[0]=="#") $l="";
45 if (substr($l,0,15)=='"Plural-Forms: '){
47 preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match);
48 $cond = str_replace('n','$n',$match[2]);
49 $out .= 'function string_plural_select_' . $lang . '($n){'."\n";
50 $out .= ' return '.$cond.';'."\n";
57 if ($k!="" && substr($l,0,7)=="msgstr "){
58 if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }
59 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
61 $v = substr($l,8,$len-10);
62 $v = preg_replace_callback($escape_s_exp,'escape_s',$v);
66 if ($k!="" && substr($l,0,7)=="msgstr["){
67 if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }
68 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
75 preg_match("|\[([0-9]*)\] (.*)|", $l, $match);
77 preg_replace_callback($escape_s_exp,'escape_s',$match[1])
79 .preg_replace_callback($escape_s_exp,'escape_s',$match[2]) .",\n";
82 if (substr($l,0,6)=="msgid_") { $ink = False; $out .= '$a->strings["'.$k.'"] = '; };
86 $k .= trim($l,"\"\r\n");
87 $k = preg_replace_callback($escape_s_exp,'escape_s',$k);
88 //$out .= '$a->strings['.$k.'] = ';
91 if (substr($l,0,6)=="msgid "){
92 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
93 if ($k!="") $out .= $arr?");\n":";\n";
95 $k = str_replace("msgid ","",$l);
97 $k = trim($k,"\"\r\n");
102 $k = preg_replace_callback($escape_s_exp,'escape_s',$k);
106 if ($inv && substr($l,0,6)!="msgstr") {
107 $v .= trim($l,"\"\r\n");
108 $v = preg_replace_callback($escape_s_exp,'escape_s',$v);
109 //$out .= '$a->strings['.$k.'] = ';
115 if ($inv) { $inv = False; $out .= '"'.$v.'"'; }
116 if ($k!="") $out .= $arr?");\n":";\n";
118 $out = str_replace(DQ_ESCAPE, '\"', $out);
119 file_put_contents($outfile, $out);
123 if (array_search(__file__,get_included_files())===0){
124 po2php_run($argv,$argc);