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, 2004 Tamlyn Rhodes 10 * @copyright (c)2003, 2004 Tamlyn Rhodes
11 * @version $Id: localecache.php,v 1.5 2005/12/15 17:18:47 tamlyn Exp $ 11 * @version $Id: localecache.php,v 1.5 2005/12/15 17:18:47 tamlyn Exp $
12 */ 12 */
13   13  
14 //require config class 14 //require config class
15 $BASEPATH = "../"; 15 $BASEPATH = "../";
16 require_once $BASEPATH."includes/config.class.php"; 16 require_once $BASEPATH."includes/config.class.php";
17 require_once $BASEPATH."includes/translator.class.php"; 17 require_once $BASEPATH."includes/translator.class.php";
18   18  
19 //get config object 19 //get config object
20 $sgConfig = sgConfig::getInstance(); 20 $sgConfig = sgConfig::getInstance();
21 $sgConfig->loadConfig($BASEPATH."singapore.ini"); 21 $sgConfig->loadConfig($BASEPATH."singapore.ini");
22 $sgConfig->base_path = $BASEPATH; 22 $sgConfig->base_path = $BASEPATH;
23   23  
24 $OUTPUTPATH = $sgConfig->base_path.$sgConfig->pathto_locale; 24 $OUTPUTPATH = $sgConfig->base_path.$sgConfig->pathto_locale;
25 $OUTPUTFILE = $sgConfig->base_path.$sgConfig->pathto_data_dir."languages.cache"; 25 $OUTPUTFILE = $sgConfig->base_path.$sgConfig->pathto_data_dir."languages.cache";
26 26
27 27
28 /** 28 /**
29 * Parses a directory and returns full path to all the files 29 * Parses a directory and returns full path to all the files
30 * matching the filter (file name suffix) 30 * matching the filter (file name suffix)
31 * 31 *
32 * @param string $dir full directory name (must end with /) 32 * @param string $dir full directory name (must end with /)
33 * @param string $filter file name suffixes separated by | (optional, default don't filter) 33 * @param string $filter file name suffixes separated by | (optional, default don't filter)
34 * @return array an array with all files 34 * @return array an array with all files
35 **/ 35 **/
36 function parseDirectory ($dir, $filter = 'php|html|tpl|inc') 36 function parseDirectory ($dir, $filter = 'php|html|tpl|inc')
37 { 37 {
38 $ret = array(); 38 $ret = array();
39 if (is_dir($dir)) { 39 if (is_dir($dir)) {
40 $d = dir($dir); 40 $d = dir($dir);
41 while (($file = $d->read()) !== false) { 41 while (($file = $d->read()) !== false) {
42 if ($file == '.' || $file == '..') continue; 42 if ($file == '.' || $file == '..') continue;
43 $fullfile = $d->path . $file; 43 $fullfile = $d->path . $file;
44 if (is_dir($fullfile)) $ret = array_merge($ret,parseDirectory($fullfile."/")); 44 if (is_dir($fullfile)) $ret = array_merge($ret,parseDirectory($fullfile."/"));
45 else if (!$filter || preg_match("/\.({$filter})$/i", $file)) $ret[] = $fullfile; 45 else if (!$filter || preg_match("/\.({$filter})$/i", $file)) $ret[] = $fullfile;
46 } 46 }
47 } 47 }
48 return $ret; 48 return $ret;
49 } 49 }
50   50  
51 function saveCache($availableLanguages, $output) 51 function saveCache($availableLanguages, $output)
52 { 52 {
53 // Open data file for writing 53 // Open data file for writing
54 $fp = @fopen($output, "wb") or die("Couldn't open file ({$output}).\n"); 54 $fp = @fopen($output, "wb") or die("Couldn't open file ({$output}).\n");
55 fwrite($fp, serialize($availableLanguages)); 55 fwrite($fp, serialize($availableLanguages));
56 return fclose($fp); 56 return fclose($fp);
57 } 57 }
58   58  
59 ?> 59 ?>
60 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 60 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
61 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 61 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
62   62  
63 <html xmlns="http://www.w3.org/1999/xhtml"> 63 <html xmlns="http://www.w3.org/1999/xhtml">
64 <head> 64 <head>
65 <title>language cache updater</title> 65 <title>language cache updater</title>
66 <link rel="stylesheet" type="text/css" href="tools.css" /> 66 <link rel="stylesheet" type="text/css" href="tools.css" />
67 </head> 67 </head>
68   68  
69 <body> 69 <body>
70   70  
71 <h1>language cache updater</h1> 71 <h1>language cache updater</h1>
72   72  
73 <p><?php 73 <p><?php
74 $files = parseDirectory($OUTPUTPATH, 'pmo'); 74 $files = parseDirectory($OUTPUTPATH, 'pmo');
75 $availableLanguages = array(); 75 $availableLanguages = array();
76 foreach ($files as $file) { 76 foreach ($files as $file) {
77 if (!preg_match("/singapore\.([\w]+)\.pmo$/i", $file, $matches)) continue; 77 if (!preg_match("/singapore\.([\w]+)\.pmo$/i", $file, $matches)) continue;
78 $i18n = Translator::getInstance($matches[1]); 78 $i18n = Translator::getInstance($matches[1]);
79 $i18n->readLanguageFile($sgConfig->base_path.$sgConfig->pathto_locale."singapore.".$i18n->language.".pmo"); 79 $i18n->readLanguageFile($sgConfig->base_path.$sgConfig->pathto_locale."singapore.".$i18n->language.".pmo");
80 $availableLanguages[$matches[1]] = $i18n->languageStrings[0]['language']; 80 $availableLanguages[$matches[1]] = $i18n->languageStrings[0]['language'];
81 echo "Added $matches[1] => ".$i18n->languageStrings[0]['language']." to available languages.<br />\n"; 81 echo "Added $matches[1] => ".$i18n->languageStrings[0]['language']." to available languages.<br />\n";
82 } 82 }
83 83
84 //add english which has no translation files 84 //add english which has no translation files
85 $availableLanguages["en"] = "English"; 85 $availableLanguages["en"] = "English";
86 86
87 ksort($availableLanguages); 87 ksort($availableLanguages);
88 if(saveCache($availableLanguages, $OUTPUTFILE)) 88 if(saveCache($availableLanguages, $OUTPUTFILE))
89 echo "Cache file saved as ".$OUTPUTFILE; 89 echo "Cache file saved as ".$OUTPUTFILE;
90 else 90 else
91 echo "Could not save cache file as ".$OUTPUTFILE; 91 echo "Could not save cache file as ".$OUTPUTFILE;
92 ?> 92 ?>
93 </p> 93 </p>
94   94  
95 <p>All operations complete. <a href="index.html">Return</a> to tools.</p> 95 <p>All operations complete. <a href="index.html">Return</a> to tools.</p>
96   96  
97 </body> 97 </body>
98 </html> 98 </html>