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