"); $files = array(); /// Get the tpl files: the filenames end with tpl and the files are in the directory templates/ and tempaltes/*/ and templates/styles/*/ $dirs = array( 'templates/', 'templates/styles/' ); chdir ('templates/'); // see bug on is_dir on php.net $handle = opendir('.'); while ($file = readdir($handle)) { if (is_dir($file) && $file != "." && $file != "..") $dirs[] = "templates/$file/"; } chdir ('styles/'); // see bug on is_dir on php.net $handle = opendir('.'); while ($file = readdir($handle)) { if (is_dir($file) && $file != "." && $file != "..") $dirs[] = "templates/styles/$file/"; } chdir ("../.."); foreach ($dirs as $dir) { $handle = opendir($dir); while ($file = readdir($handle)) { if ($file == '.' || $file == '..') continue; if (substr($file, strlen($file) - 3, 3) == "tpl") { print ("File: $dir$file
"); $files[] = $dir . $file; } } closedir ($handle); } /// get the php files: the filenames end with php and the files are located in the list of directories ./, modules/; lib/, lib/*/, Smarty/plugins/ $dirs = array( './', 'modules/', 'lib/', 'Smarty/plugins/' ); chdir ('lib/'); $handle = opendir('.'); while ($file = readdir($handle)) { if (is_dir($file) && $file != "." && $file != "..") $dirs[] = "lib/$file/"; } chdir (".."); foreach ($dirs as $dir) { $handle = opendir($dir); while ($file = readdir($handle)) { if ($file == '.' || $file == '..') continue; if (substr($file, strlen($file) - 3, 3) == "php") { print ("File: $dir$file
"); $files[] = $dir . $file; } } closedir ($handle); } foreach ($languages as $sel) { unset ($lang); unset ($used); include ("lang/$sel/language.php"); $nbTrads = count($lang); $fw = fopen("lang/$sel/new_language.php", 'w+'); print ("<?php\n
\$lang=Array(\n
"); // the generated comment coding:utf-8 is for the benefit of emacs // The comment must be on the very first line in the file. fwrite($fw, " "' . $lang[$word] . '",' . "\n
"); //fwrite($fw,'"'.$word.'" => "'.$lang[$word].'",'."\n"); } else { print ('+++"' . $word . '" => "' . $word . '",' . "\n
"); $lang[$word] = $word; //fwrite($fw,'"'.$word.'" => "'.$word.'",'."\n"); } } } /// (?s) for multiline /// known bug: collects also the function xxxtra("xx") - needs only to collect hawtra("xxx") and tra("xxx") preg_match_all("/(?s)tra[ \t]*\( *\"([^\"]+)\"[ \t]*\)/", $data, $words); foreach (array_unique($words[1])as $word) { if (!isset($used[$word])) $used[$word] = 1; if (isset($lang[$word])) { print ('"' . $word . '" => "' . $lang[$word] . '",' . "\n
"); //fwrite($fw,'"'.$word.'" => "'.$lang[$word].'",'."\n"); } else { print ('+++"' . $word . '" => "' . $word . '",' . "\n
"); $lang[$word] = $word; //fwrite($fw,'"'.$word.'" => "'.$word.'",'."\n"); } } preg_match_all("/(?s)tra[ \t]*\( *\'([^\']+)\'[ \t]*\)/", $data, $words); foreach (array_unique($words[1])as $word) { if (!isset($used[$word])) $used[$word] = 1; if (isset($lang[$word])) { print ('"' . $word . '" => "' . $lang[$word] . '",' . "\n
"); } else { print ('+++"' . $word . '" => "' . $word . '",' . "\n
"); $lang[$word] = $word; } } } print ('"' . '##end###' . '" => "' . '###end###' . '"' . ");?>\n
"); $nb = 0; foreach ($lang as $key => $val) { if ($key == '##end###' && $val == '###end###') continue; // backslash $ and \n fwrite($fw, '"' . str_replace("\$", "\\\$", str_replace("\n", "\\n", $key)). '" => "' . str_replace("\$", "\\\$", str_replace("\n", "\\n", $val)). '",'); if (++$nb == $nbTrads) fwrite($fw, "//##First new line"); if (isset($used[$key])) fwrite($fw, "\n"); else fwrite($fw, "//perhaps not used\n"); } fwrite($fw, '"' . '##end###' . '" => "' . '###end###' . '");' . "\n" . '?>' . "\n"); fclose ($fw); @unlink ("lang/$sel/old.php"); @rename("lang/$sel/language.php", "lang/$sel/old.php"); rename("lang/$sel/new_language.php", "lang/$sel/language.php"); } ?>