Projekt

Obecné

Profil

Stáhnout (1.36 KB) Statistiky
| Větev: | Tag: | Revize:
1
#!/usr/bin/php -f
2
<?php
3
/**
4
	* This script converts a po file generated from english.php by php2po
5
	* into a new_language.php
6
	* The resulted php file still needs some manual editing 
7
	* (header & $lang['app...'] variables)
8
	* 
9
	* $Id: po2php,v 1.1 2004/11/10 01:28:10 chriskl Exp $
10
	*/
11

    
12
switch ($argc)
13
{
14
	case 2:
15
		$dlang = $argv[1];
16
		break;
17
	default:
18
		echo "\nUsage: $argv[0] dstlang\n\n";
19
		exit();
20
}
21

    
22

    
23
if (!file_exists($dlang.".po"))
24
{
25
	echo "\nError: file not found: $dlang.po\n\n";
26
	exit();
27
}
28

    
29
if (file_exists($dlang.".php"))
30
{
31
	echo "\nError: file $dlang.php already exists\n\n";
32
	exit();
33
}
34

    
35
$scode = file ($dlang.".po");
36

    
37
// Create lang.php file
38
if (! $fres = fopen($dlang.".php", "w"))
39
{
40
	echo "\nError: cannot open file ".$dlang.".php for writing\n\n";
41
	exit();
42
}
43

    
44
fwrite($fres, "<?php\n\n\n");
45

    
46
// Parse source code
47
for ($i = 0; $i < count($scode); $i++)
48
{
49
	if (preg_match("/^#. group (.*)$/", $scode[$i], $ret))
50
	{
51
		fwrite($fres, "\n\t//".$ret[1]."\n");
52
	}
53
	elseif (preg_match("/^#. str (.*)$/", $scode[$i], $ret))
54
	{
55
		$langvar = $ret[1];
56
	}
57
	elseif (preg_match("/^msgid \"(.*)\"$/", $scode[$i], $ret))
58
	{
59
		$base = $ret[1];
60
	}
61
	elseif (preg_match("/^msgstr \"(.*)\"$/", $scode[$i], $ret))
62
	{
63
		if (! $ret[1])
64
			$ret[1] = $base;
65
		
66
		fwrite($fres, "\t\$lang['".$langvar."'] = '".str_replace('\\"', '"', $ret[1])."';\n");
67
	}
68
}
69

    
70
fwrite($fres, "\n\n\n?>\n");
71

    
72
fclose($fres);
73

    
74
?>
(20-20/32)