3 function po2php_run($argv, $argc) {
6 print "Usage: ".$argv[0]." <file.po>\n\n";
11 $outfile = dirname($pofile)."/strings.php";
13 if (!file_exists($pofile)){
14 print "Unable to find '$pofile'\n";
18 print "Out to '$outfile'\n";
22 $infile = file($pofile);
26 foreach ($infile as $l) {
28 if (substr($l,0,15)=='"Plural-Forms: '){
30 preg_match("|nplurals=([0-9]*); plural=(.*);|", $l, $match);
31 $cond = str_replace('n','$n',$match[2]);
32 $out .= 'function string_plural_select($n){'."\n";
33 $out .= ' return '.$cond.';'."\n";
37 if (substr($l,0,6)=="msgid "){
38 if ($k!="") $out .= $arr?");\n":";\n";
40 $k = substr($l,6, $len-7);
42 $out .= '$a->strings['.$k.'] = ';
48 if ($k!="" && substr($l,0,7)=="msgstr "){
49 $v = substr($l,7,$len-8);
52 if ($k!="" && substr($l,0,7)=="msgstr["){
58 preg_match("|\[([0-9]*)\] (.*)|", $l, $match);
59 $out .= "\t". $match[1]." => ". $match[2] .",\n";
64 if ($k!="") $out .= $arr?");\n":";\n";
66 file_put_contents($outfile, $out);
70 if (array_search(__file__,get_included_files())===0){
71 po2php_run($argv,$argc);