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