1
|
#!/usr/bin/php -f
|
2
|
<?php
|
3
|
/**
|
4
|
* This script creates a po file for for a new language.
|
5
|
* based on english.php
|
6
|
* Be aware that the variables in the 'Language and character set'
|
7
|
* section ($lang['app...']) are not for translation, but settings.
|
8
|
*
|
9
|
* $Id: php2po,v 1.1 2004/11/10 01:28:10 chriskl Exp $
|
10
|
*/
|
11
|
|
12
|
|
13
|
switch ($argc)
|
14
|
{
|
15
|
case 2:
|
16
|
$slang = 'english';
|
17
|
$dlang = $argv[1];
|
18
|
break;
|
19
|
case 3:
|
20
|
$slang = $argv[1];
|
21
|
$dlang = $argv[2];
|
22
|
break;
|
23
|
default:
|
24
|
echo "\nUsage: $argv[0] [srclang] dstlang\n\n";
|
25
|
exit();
|
26
|
}
|
27
|
|
28
|
$scode = file ($slang.".php");
|
29
|
|
30
|
// Parse source code
|
31
|
for ($i = 0; $i < count($scode); $i++)
|
32
|
{
|
33
|
$scode[$i] = trim($scode[$i]);
|
34
|
if (substr($scode[$i], 0, 2) == '//')
|
35
|
{
|
36
|
$group = substr($scode[$i], 2);
|
37
|
$src[$group] = array();
|
38
|
}
|
39
|
|
40
|
preg_match("/.lang\['(.*?)'\] = '(.*?)';/", $scode[$i], $ret);
|
41
|
|
42
|
if (count($ret))
|
43
|
{
|
44
|
$src[$group][$ret[1]] = $ret[2];
|
45
|
}
|
46
|
}
|
47
|
|
48
|
// Parse destination (if it exists)
|
49
|
if (file_exists($dlang.".php"))
|
50
|
{
|
51
|
$dcode = file ($dlang.".php");
|
52
|
|
53
|
for ($i = 0; $i < count($dcode); $i++)
|
54
|
{
|
55
|
$dcode[$i] = trim($dcode[$i]);
|
56
|
|
57
|
preg_match("/.lang\['(.*?)'\] = '(.*?)';/", $dcode[$i], $ret);
|
58
|
|
59
|
if (count($ret))
|
60
|
{
|
61
|
$dst[$ret[1]] = $ret[2];
|
62
|
}
|
63
|
}
|
64
|
}
|
65
|
|
66
|
// Create po file
|
67
|
if (! $fres = fopen($dlang.".po", "w"))
|
68
|
{
|
69
|
echo "\nError: cannot open file ".$dlang.".po for writing\n\n";
|
70
|
exit();
|
71
|
}
|
72
|
|
73
|
fwrite($fres, "#\n#\n#\n#\n\n\n\n\n");
|
74
|
fwrite($fres, "msgid \"\"\n");
|
75
|
fwrite($fres, "msgstr \"\"\n\n\n\n");
|
76
|
|
77
|
foreach ($src as $group => $strings)
|
78
|
{
|
79
|
fwrite($fres, "\n");
|
80
|
fwrite($fres, "#. group $group\n");
|
81
|
|
82
|
foreach($strings as $var => $string)
|
83
|
{
|
84
|
$string = str_replace('"', '\\"', $string);
|
85
|
fwrite($fres, "#. str $var\n");
|
86
|
fwrite($fres, "msgid \"$string\"\n");
|
87
|
fwrite($fres, "msgstr \"");
|
88
|
if ($dst[$var])
|
89
|
{
|
90
|
$tstring = str_replace('"', '\\"', $dst[$var]);
|
91
|
fwrite($fres, $tstring);
|
92
|
}
|
93
|
fwrite($fres, "\"\n\n");
|
94
|
}
|
95
|
|
96
|
}
|
97
|
|
98
|
fclose($fres);
|
99
|
|
100
|
?>
|