228 |
kaklik |
1 |
<?php |
|
|
2 |
|
|
|
3 |
/** |
|
|
4 |
* This file merges the two PO template files (singapore.pot and singapore.admin.pot) |
|
|
5 |
* with all existing language files (singapore.LANG.po) |
|
|
6 |
* |
|
|
7 |
* @author Joel Sjögren <joel dot sjogren at nonea dot se> |
|
|
8 |
* @author Tamlyn Rhodes <tam at zenology dot co dot uk> |
|
|
9 |
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License |
|
|
10 |
* @copyright (c)2003-2005 Tamlyn Rhodes |
|
|
11 |
* @version $Id: merge.php,v 1.8 2006/05/08 09:40:02 thepavian Exp $ |
|
|
12 |
*/ |
|
|
13 |
|
|
|
14 |
// Programs to call (insert path to them if necessary) |
|
|
15 |
$GETTEXT_MERGE = "msgmerge"; |
|
|
16 |
$BASEPATH = realpath("..")."/"; |
|
|
17 |
|
|
|
18 |
//require config class |
|
|
19 |
require_once $BASEPATH."includes/config.class.php"; |
|
|
20 |
|
|
|
21 |
//get config object |
|
|
22 |
$config = sgConfig::getInstance(); |
|
|
23 |
$config->loadConfig($BASEPATH."singapore.ini"); |
|
|
24 |
|
|
|
25 |
$OUTPUTPATH = $BASEPATH.$config->pathto_locale; |
|
|
26 |
$standardPot = $OUTPUTPATH."singapore.pot"; |
|
|
27 |
$adminPot = $OUTPUTPATH."singapore.admin.pot"; |
|
|
28 |
$createbackups = true; |
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
/** |
|
|
33 |
* Parses a directory and returns full path to all the files |
|
|
34 |
* matching the filter (file name suffix) |
|
|
35 |
* |
|
|
36 |
* @param string $dir full directory name (must end with /) |
|
|
37 |
* @param string $filter file name suffixes separated by | (optional, default don't filter) |
|
|
38 |
* @return array an array with all files |
|
|
39 |
**/ |
|
|
40 |
function parseDirectory ($dir, $filter = 'php|html|tpl|inc') |
|
|
41 |
{ |
|
|
42 |
$ret = array(); |
|
|
43 |
if (is_dir($dir)) { |
|
|
44 |
$d = dir($dir); |
|
|
45 |
while (($file = $d->read()) !== false) { |
|
|
46 |
if ($file == '.' || $file == '..') continue; |
|
|
47 |
$fullfile = $d->path . $file; |
|
|
48 |
if (is_dir($fullfile)) $ret = array_merge($ret,parseDirectory($fullfile."/")); |
|
|
49 |
else if (!$filter || preg_match("/\.({$filter})$/i", $file)) $ret[] = $fullfile; |
|
|
50 |
} |
|
|
51 |
} |
|
|
52 |
return $ret; |
|
|
53 |
} |
|
|
54 |
|
|
|
55 |
|
|
|
56 |
?> |
|
|
57 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
|
|
58 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
|
59 |
|
|
|
60 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|
|
61 |
<head> |
|
|
62 |
<title>i18n string merger</title> |
|
|
63 |
<link rel="stylesheet" type="text/css" href="tools.css" /> |
|
|
64 |
</head> |
|
|
65 |
|
|
|
66 |
<body> |
|
|
67 |
|
|
|
68 |
<h1>i18n string merger</h1> |
|
|
69 |
|
|
|
70 |
<p><?php |
|
|
71 |
$files = parseDirectory($OUTPUTPATH, 'po'); |
|
|
72 |
foreach ($files as $file) { |
|
|
73 |
if (!preg_match("/singapore\.[\w]+\.po$/i", $file)) continue; |
|
|
74 |
$backup = $file . '.bak'; |
|
|
75 |
if (file_exists($backup)) @unlink($backup); |
|
|
76 |
@rename($file, $backup); |
|
|
77 |
$res = shell_exec("{$GETTEXT_MERGE} --strict \"{$backup}\" \"" . $standardPot . "\" > \"{$file}\""); |
|
|
78 |
if (trim($res)) echo "Something seemed to go wrong with msgmerge:\n" . $res . "\n"; |
|
|
79 |
else echo "$standardPot merged with $file<br />"; |
|
|
80 |
|
|
|
81 |
// Remove backup? |
|
|
82 |
if (!@$createbackups) @unlink($backup); |
|
|
83 |
|
|
|
84 |
//set permissions on new POT file |
|
|
85 |
@chmod($standardPot, octdec($config->file_mode)); |
|
|
86 |
} |
|
|
87 |
|
|
|
88 |
///////admin/////////// |
|
|
89 |
|
|
|
90 |
$files = parseDirectory($OUTPUTPATH, 'po'); |
|
|
91 |
foreach ($files as $file) { |
|
|
92 |
if (!preg_match("/singapore\.admin\.[\w]+\.po$/i", $file)) continue; |
|
|
93 |
$backup = $file . '.bak'; |
|
|
94 |
if (file_exists($backup)) @unlink($backup); |
|
|
95 |
@rename($file, $backup); |
|
|
96 |
$res = shell_exec("{$GETTEXT_MERGE} --strict \"{$backup}\" \"" . $adminPot . "\" > \"{$file}\""); |
|
|
97 |
if (trim($res)) echo "Something seemed to go wrong with msgmerge:\n" . $res . "\n"; |
|
|
98 |
else echo "$adminPot merged with $file<br />"; |
|
|
99 |
|
|
|
100 |
// Remove backup? |
|
|
101 |
if (!@$createbackups) @unlink($backup); |
|
|
102 |
|
|
|
103 |
//set permissions on new POT file |
|
|
104 |
@chmod($adminPot, octdec($config->file_mode)); |
|
|
105 |
} |
|
|
106 |
|
|
|
107 |
?> |
|
|
108 |
</p> |
|
|
109 |
|
|
|
110 |
<p>Once you have translated the updated PO files you may |
|
|
111 |
<a href="compile.php">compile</a> them into PHP serialized objects for use with |
|
|
112 |
singapore.</p> |
|
|
113 |
|
|
|
114 |
</body> |
|
|
115 |
</html> |