228 |
kaklik |
1 |
<?php |
|
|
2 |
|
|
|
3 |
/** |
|
|
4 |
* This file searches for strings in all project files matching the filter and |
|
|
5 |
* creates two PO template files (singapore.pot and singapore.admin.pot) |
|
|
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: extract.php,v 1.14 2006/06/24 22:36:15 tamlyn Exp $ |
|
|
12 |
*/ |
|
|
13 |
|
|
|
14 |
// Programs to call (insert path to them if necessary) |
|
|
15 |
$GETTEXT_EXTRACT = "xgettext"; |
|
|
16 |
$BASEPATH = realpath("..")."/"; |
|
|
17 |
|
|
|
18 |
|
|
|
19 |
//require config class |
|
|
20 |
require_once $BASEPATH."includes/config.class.php"; |
|
|
21 |
|
|
|
22 |
//get config object |
|
|
23 |
$config = sgConfig::getInstance(); |
|
|
24 |
$config->loadConfig($BASEPATH."singapore.ini"); |
|
|
25 |
|
|
|
26 |
$OUTPUTPATH = $BASEPATH.$config->pathto_locale; |
|
|
27 |
$standardPot = $OUTPUTPATH."singapore.pot"; |
|
|
28 |
$adminPot = $OUTPUTPATH."singapore.admin.pot"; |
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
/** |
|
|
34 |
* Parses a directory and returns full path to all the files |
|
|
35 |
* matching the filter (file name suffix) |
|
|
36 |
* |
|
|
37 |
* @param string $dir full directory name (must end with /) |
|
|
38 |
* @param string $filter file name suffixes separated by | (optional, default don't filter) |
|
|
39 |
* @return array an array with all files |
|
|
40 |
**/ |
|
|
41 |
function parseDirectory ($dir, $filter = "php|html|tpl|inc") |
|
|
42 |
{ |
|
|
43 |
$ret = array(); |
|
|
44 |
if (is_dir($dir)) { |
|
|
45 |
$d = dir($dir); |
|
|
46 |
while (($file = $d->read()) !== false) { |
|
|
47 |
if ($file == '.' || $file == '..') continue; |
|
|
48 |
$fullfile = $d->path . $file; |
|
|
49 |
if (is_dir($fullfile)) $ret = array_merge($ret,parseDirectory($fullfile."/")); |
|
|
50 |
else if (!$filter || preg_match("/\.({$filter})$/i", $file)) $ret[] = $fullfile; |
|
|
51 |
} |
|
|
52 |
} |
|
|
53 |
return $ret; |
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
|
|
|
57 |
?> |
|
|
58 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
|
|
59 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
|
60 |
|
|
|
61 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|
|
62 |
<head> |
|
|
63 |
<title>i18n string extractor</title> |
|
|
64 |
<link rel="stylesheet" type="text/css" href="tools.css" /> |
|
|
65 |
</head> |
|
|
66 |
|
|
|
67 |
<body> |
|
|
68 |
|
|
|
69 |
<h1>i18n string extractor</h1> |
|
|
70 |
|
|
|
71 |
<p><?php |
|
|
72 |
// Create tempfile |
|
|
73 |
$temp = $OUTPUTPATH."/".'~tempfile'; |
|
|
74 |
$fp = fopen($temp, 'wb') or die("Couldn't open tempfile {$temp} for writing.\n"); |
|
|
75 |
|
|
|
76 |
// Get all files matching pattern in current template |
|
|
77 |
$files = parseDirectory("../".$config->pathto_templates.$config->default_template.'/'); |
|
|
78 |
$files[] = "../includes/image.class.php"; |
|
|
79 |
$files[] = "../includes/item.class.php"; |
|
|
80 |
$files[] = "../includes/gallery.class.php"; |
|
|
81 |
$files[] = "../includes/singapore.class.php"; |
|
|
82 |
$files[] = "../includes/user.class.php"; |
|
|
83 |
fwrite($fp, implode("\n", $files)); |
|
|
84 |
|
|
|
85 |
// Close tempfile |
|
|
86 |
fclose($fp); |
|
|
87 |
|
|
|
88 |
// Call gettext |
|
|
89 |
$res = shell_exec("{$GETTEXT_EXTRACT} --debug --keyword=_g --keyword=_ng:1,2 --keyword=__g -C -F --output=\"" . $standardPot . "\" --files-from=\"" . $temp . "\""); |
|
|
90 |
if (trim($res)) die("Something seemed to go wrong with gettext:\n" . $res . "\n"); |
|
|
91 |
else echo "Standard strings extracted $standardPot<br />"; |
|
|
92 |
|
|
|
93 |
// Remove tempfile |
|
|
94 |
unlink($temp); |
|
|
95 |
|
|
|
96 |
//set permissions on new POT file |
|
|
97 |
@chmod($standardPot, octdec($config->file_mode)); |
|
|
98 |
|
|
|
99 |
|
|
|
100 |
///////admin/////////// |
|
|
101 |
|
|
|
102 |
// Create tempfile |
|
|
103 |
$temp = $OUTPUTPATH."/".'~tempfile'; |
|
|
104 |
$fp = fopen($temp, 'w') or die("Couldn't open tempfile {$temp} for writing.\n"); |
|
|
105 |
|
|
|
106 |
// Get all files matching pattern in current template |
|
|
107 |
$files = parseDirectory("../".$config->pathto_templates.$config->admin_template_name.'/'); |
|
|
108 |
$files[] = "../includes/admin.class.php"; |
|
|
109 |
$files[] = "../admin.php"; |
|
|
110 |
fwrite($fp, implode("\n", $files)); |
|
|
111 |
|
|
|
112 |
// Close tempfile |
|
|
113 |
fclose($fp); |
|
|
114 |
|
|
|
115 |
// Call gettext |
|
|
116 |
$res = shell_exec("{$GETTEXT_EXTRACT} --debug --keyword=_g --keyword=_ng:1,2 -C -F -x \"" . $standardPot . "\" --output=\"" . $adminPot . "\" --files-from=\"" . $temp . "\""); |
|
|
117 |
if (trim($res)) die("Something seemed to go wrong with gettext:\n" . $res . "\n"); |
|
|
118 |
else echo "Admin strings extracted to $adminPot<br />"; |
|
|
119 |
|
|
|
120 |
// Remove tempfile |
|
|
121 |
unlink($temp); |
|
|
122 |
|
|
|
123 |
//set permissions on new POT file |
|
|
124 |
@chmod($adminPot, octdec($config->file_mode)); |
|
|
125 |
|
|
|
126 |
?> |
|
|
127 |
</p> |
|
|
128 |
|
|
|
129 |
<p>You may now <a href="merge.php">merge</a> the strings into all previously |
|
|
130 |
translated PO files.</p> |
|
|
131 |
|
|
|
132 |
</body> |
|
|
133 |
</html> |