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)));
23 if (!file_exists($pofile)){
24 print "Unable to find '$pofile'\n";
28 print "Out to '$outfile'\n";
32 $infile = file($pofile);
38 $escape_s_exp = '|[^\\\\]\$[a-z]|';
39 function escape_s($match){
40 return str_replace('$','\$',$match[0]);
42 foreach ($infile as $l) {
43 $l = str_replace('\"', DQ_ESCAPE, $l);
48 if (substr($l,0,15) == '"Plural-Forms: '){
50 preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match);
51 $cond = str_replace('n','$n',$match[2]);
52 // define plural select function if not already defined
53 $fnname = 'string_plural_select_' . $lang;
54 $out .= 'if (! function_exists("'.$fnname.'")) {'."\n";
55 $out .= 'function '. $fnname . '($n){'."\n";
56 $out .= ' return '.$cond.';'."\n";
60 if ($k!="" && substr($l,0,7) == "msgstr "){
63 $out .= '$a->strings["'.$k.'"] = ';
70 $v = substr($l,8,$len-10);
71 $v = preg_replace_callback($escape_s_exp,'escape_s',$v);
75 if ($k!="" && substr($l,0,7) == "msgstr["){
78 $out .= '$a->strings["'.$k.'"] = ';
90 preg_match("|\[([0-9]*)\] (.*)|", $l, $match);
92 preg_replace_callback($escape_s_exp,'escape_s',$match[1])
94 .preg_replace_callback($escape_s_exp,'escape_s',$match[2]) .",\n";
97 if (substr($l,0,6)=="msgid_") { $ink = False; $out .= '$a->strings["'.$k.'"] = '; };
100 $k .= trim($l,"\"\r\n");
101 $k = preg_replace_callback($escape_s_exp,'escape_s',$k);
102 //$out .= '$a->strings['.$k.'] = ';
105 if (substr($l,0,6)=="msgid "){
111 $out .= $arr?");\n":";\n";
114 $k = str_replace("msgid ","",$l);
116 $k = trim($k,"\"\r\n");
121 $k = preg_replace_callback($escape_s_exp,'escape_s',$k);
125 if ($inv && substr($l,0,6)!="msgstr") {
126 $v .= trim($l,"\"\r\n");
127 $v = preg_replace_callback($escape_s_exp,'escape_s',$v);
128 //$out .= '$a->strings['.$k.'] = ';
139 $out .= $arr?");\n":";\n";
142 $out = str_replace(DQ_ESCAPE, '\"', $out);
143 file_put_contents($outfile, $out);
147 if (array_search(__file__,get_included_files())===0){
148 po2php_run($_SERVER["argv"],$_SERVER["argc"]);