File: php2po

package info (click to toggle)
phppgadmin 4.2.3-1.1squeeze2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 5,396 kB
  • ctags: 6,174
  • sloc: php: 68,599; makefile: 215; sh: 41; sql: 16; awk: 9
file content (100 lines) | stat: -rwxr-xr-x 1,987 bytes parent folder | download | duplicates (6)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/php -f
<?php
/**
	* This script creates a po file for for a new language.
	* based on english.php
	* Be aware that the variables in the 'Language and character set'
	* section ($lang['app...']) are not for translation, but settings.
	* 
	* $Id: php2po,v 1.1 2004/11/10 01:28:10 chriskl Exp $
	*/


switch ($argc)
{
	case 2:
		$slang = 'english';
		$dlang = $argv[1];
		break;
	case 3:
		$slang = $argv[1];
		$dlang = $argv[2];
		break;
	default:
		echo "\nUsage: $argv[0] [srclang] dstlang\n\n";
		exit();
}

$scode = file ($slang.".php");

// Parse source code
for ($i = 0; $i < count($scode); $i++)
{
	$scode[$i] = trim($scode[$i]);
	if (substr($scode[$i], 0, 2) == '//')
	{
		$group = substr($scode[$i], 2);
		$src[$group] = array();
	}
	
	preg_match("/.lang\['(.*?)'\] = '(.*?)';/", $scode[$i], $ret);
	
	if (count($ret))
	{
		$src[$group][$ret[1]] = $ret[2];
	}
}

// Parse destination (if it exists)
if (file_exists($dlang.".php"))
{
	$dcode = file ($dlang.".php");
	
	for ($i = 0; $i < count($dcode); $i++)
	{
		$dcode[$i] = trim($dcode[$i]);
		
		preg_match("/.lang\['(.*?)'\] = '(.*?)';/", $dcode[$i], $ret);
		
		if (count($ret))
		{
			$dst[$ret[1]] = $ret[2];
		}
	}
}

// Create po file
if (! $fres = fopen($dlang.".po", "w"))
{
	echo "\nError: cannot open file ".$dlang.".po for writing\n\n";
	exit();
}

fwrite($fres, "#\n#\n#\n#\n\n\n\n\n");
fwrite($fres, "msgid \"\"\n");
fwrite($fres, "msgstr \"\"\n\n\n\n");

foreach ($src as $group => $strings)
{
	fwrite($fres, "\n");
	fwrite($fres, "#. group $group\n");
	
	foreach($strings as $var => $string)
	{
		$string = str_replace('"', '\\"', $string);
		fwrite($fres, "#. str $var\n");
		fwrite($fres, "msgid \"$string\"\n");
		fwrite($fres, "msgstr \"");
		if ($dst[$var])
		{
			$tstring = str_replace('"', '\\"', $dst[$var]);
			fwrite($fres, $tstring);
		}
		fwrite($fres, "\"\n\n");
	}
	
}

fclose($fres);

?>