File: po2php

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 (74 lines) | stat: -rwxr-xr-x 1,465 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
#!/usr/bin/php -f
<?php
/**
	* This script converts a po file generated from english.php by php2po
	* into a new_language.php
	* The resulted php file still needs some manual editing 
	* (header & $lang['app...'] variables)
	* 
	* $Id: po2php,v 1.1 2004/11/10 01:28:10 chriskl Exp $
	*/

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


if (!file_exists($dlang.".po"))
{
	echo "\nError: file not found: $dlang.po\n\n";
	exit();
}

if (file_exists($dlang.".php"))
{
	echo "\nError: file $dlang.php already exists\n\n";
	exit();
}

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

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

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

// Parse source code
for ($i = 0; $i < count($scode); $i++)
{
	if (preg_match("/^#. group (.*)$/", $scode[$i], $ret))
	{
		fwrite($fres, "\n\t//".$ret[1]."\n");
	}
	elseif (preg_match("/^#. str (.*)$/", $scode[$i], $ret))
	{
		$langvar = $ret[1];
	}
	elseif (preg_match("/^msgid \"(.*)\"$/", $scode[$i], $ret))
	{
		$base = $ret[1];
	}
	elseif (preg_match("/^msgstr \"(.*)\"$/", $scode[$i], $ret))
	{
		if (! $ret[1])
			$ret[1] = $base;
		
		fwrite($fres, "\t\$lang['".$langvar."'] = '".str_replace('\\"', '"', $ret[1])."';\n");
	}
}

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

fclose($fres);

?>