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