aboutsummaryrefslogtreecommitdiffstats
path: root/util/php2po.php
blob: d3ce0a5af54a680ebaafab988f5598df90fa4e1d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

	if(! class_exists('App')) {
		class TmpA {
			public $strings = Array();
		}
		$a = new TmpA();
	}

	if ($argc!=2) {
		print "Usage: ".$argv[0]." <strings.php>\n\n";
		return;
	}
	
	$phpfile = $argv[1];
	$pofile = dirname($phpfile)."/messages.po";

	if (!file_exists($phpfile)){
		print "Unable to find '$phpfile'\n";
		return;
	}

	include_once($phpfile);

	print "Out to '$pofile'\n";
	
	$out = "";	
	$infile = file($pofile);
	$k="";
	$ink = False;
	foreach ($infile as $l) {
	
		if ($k!="" && substr($l,0,7)=="msgstr "){
			$ink = False;
			$v = '""';
			//echo "DBG: k:'$k'\n";
			if (isset($a->strings[$k])) {
				$v= '"'.$a->strings[$k].'"';
				//echo "DBG\n";
				//var_dump($k, $v, $a->strings[$k], $v);
				//echo "/DBG\n";
				
			}
			//echo "DBG: v:'$v'\n";
			$l = "msgstr ".$v."\n";
		}
	
		if (substr($l,0,6)=="msgid_" || substr($l,0,7)=="msgstr[" )$ink = False;;
	
		if ($ink) {
			$k .= trim($l,"\"\r\n");
			$k = str_replace('\"','"',$k); 
		}
		
		if (substr($l,0,6)=="msgid "){
			$arr=False;
			$k = str_replace("msgid ","",$l);
			if ($k != '""' ) {
				$k = trim($k,"\"\r\n");
				$k = str_replace('\"','"',$k);
			} else {
				$k = "";
			}
			$ink = True;
		}
		
		$out .= $l;
	}
	//echo $out;
	file_put_contents($pofile, $out);
?>