]> git.mxchange.org Git - friendica.git/blob - util/php2po.php
Merge remote branch 'upstream/master'
[friendica.git] / util / php2po.php
1 <?php
2
3         if(! class_exists('App')) {
4                 class TmpA {
5                         public $strings = Array();
6                 }
7                 $a = new TmpA();
8         }
9
10         if ($argc!=2) {
11                 print "Usage: ".$argv[0]." <strings.php>\n\n";
12                 return;
13         }
14         
15         $phpfile = $argv[1];
16         $pofile = dirname($phpfile)."/messages.po";
17
18         if (!file_exists($phpfile)){
19                 print "Unable to find '$phpfile'\n";
20                 return;
21         }
22
23         include_once($phpfile);
24
25         print "Out to '$pofile'\n";
26         
27         $out = "";      
28         $infile = file($pofile);
29         $k="";
30         $ink = False;
31         foreach ($infile as $l) {
32         
33                 if ($k!="" && substr($l,0,7)=="msgstr "){
34                         $ink = False;
35                         $v = '""';
36                         //echo "DBG: k:'$k'\n";
37                         if (isset($a->strings[$k])) {
38                                 $v= '"'.$a->strings[$k].'"';
39                                 //echo "DBG\n";
40                                 //var_dump($k, $v, $a->strings[$k], $v);
41                                 //echo "/DBG\n";
42                                 
43                         }
44                         //echo "DBG: v:'$v'\n";
45                         $l = "msgstr ".$v."\n";
46                 }
47         
48                 if (substr($l,0,6)=="msgid_" || substr($l,0,7)=="msgstr[" )$ink = False;;
49         
50                 if ($ink) {
51                         $k .= trim($l,"\"\r\n");
52                         $k = str_replace('\"','"',$k); 
53                 }
54                 
55                 if (substr($l,0,6)=="msgid "){
56                         $arr=False;
57                         $k = str_replace("msgid ","",$l);
58                         if ($k != '""' ) {
59                                 $k = trim($k,"\"\r\n");
60                                 $k = str_replace('\"','"',$k);
61                         } else {
62                                 $k = "";
63                         }
64                         $ink = True;
65                 }
66                 
67                 $out .= $l;
68         }
69         //echo $out;
70         file_put_contents($pofile, $out);
71 ?>