]> git.mxchange.org Git - friendica.git/blob - util/po2php.php
Changed 'mo' with 'po'.....
[friendica.git] / util / po2php.php
1 <?php
2
3 function po2php_run($argv, $argc) {
4
5         if ($argc!=2) {
6                 print "Usage: ".$argv[0]." <file.po>\n\n";
7                 return;
8         }
9         
10         $pofile = $argv[1];
11         $outfile = dirname($pofile)."/strings.php";
12         
13         if (!file_exists($pofile)){
14                 print "Unable to find '$pofile'\n";
15                 return;
16         }
17         
18         print "Out to '$outfile'\n";
19         
20         $out="<?php\n\n";
21         
22         $infile = file($pofile);
23         $k="";
24         $arr = False;
25         
26         foreach ($infile as $l) {
27                 $len = strlen($l);
28                 if (substr($l,0,15)=='"Plural-Forms: '){
29                         $match=Array();
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";
34                         $out .= '}'."\n";
35                 }
36                 
37                 if (substr($l,0,6)=="msgid "){
38                         if ($k!="") $out .= $arr?");\n":";\n";
39                         $arr=False;
40                         $k = substr($l,6, $len-7);
41                         if ($k != '""' ) {
42                                 $out .= '$a->strings['.$k.'] = ';
43                         } else {
44                                 $k = "";
45                         }
46                 }
47
48                 if ($k!="" && substr($l,0,7)=="msgstr "){
49                         $v = substr($l,7,$len-8);
50                         $out .= $v;
51                 }
52                 if ($k!="" && substr($l,0,7)=="msgstr["){
53                         if (!$arr) {
54                                 $arr=True;
55                                 $out .= "array(\n";
56                         }
57                         $match=Array();
58                         preg_match("|\[([0-9]*)\] (.*)|", $l, $match);
59                         $out .= "\t". $match[1]." => ". $match[2] .",\n";
60                 }
61                 
62         }
63         
64         if ($k!="") $out .= $arr?");\n":";\n";
65         
66         file_put_contents($outfile, $out);
67         
68 }
69
70 if (array_search(__file__,get_included_files())===0){
71   po2php_run($argv,$argc);
72 }