Permalink
Browse files

Use numeric language IDs to save bytes

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@414 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
jakubvrana
jakubvrana committed May 23, 2008
1 parent d541175 commit 4738060aa404540c2d7cd1ef9f1be77d2285f072
Showing with 27 additions and 2 deletions.
  1. +27 −2 _compile.php
View
@@ -13,14 +13,37 @@ function remove_lang($match) {
return ($match[1] && $match[4] ? $s : "$match[1]'" . add_apo_slashes($s) . "'$match[4]");
}
+$lang_ids = array();
+function lang_ids($match) {
+ global $lang_ids;
+ return 'lang(' . $lang_ids[stripslashes($match[1])] . $match[2];
+}
+
function put_file($match) {
+ global $lang_ids;
if ($match[3] == './lang/$LANG.inc.php') {
if ($_COOKIE["lang"]) {
return "";
}
$return = "";
- foreach (glob("./lang/*.inc.php") as $filename) {
- $return .= "case '" . basename($filename, '.inc.php') . "': " . substr(file_get_contents($filename), 6) . "break;\n";
+ foreach (glob("lang/*.inc.php") as $filename) {
+ include $filename;
+
+ foreach ($translations as $key => $val) {
+ if (!isset($lang_ids[$key])) {
+ $lang_ids[$key] = count($lang_ids);
+ }
+ }
+ $translation_ids = array_flip($lang_ids);
+ foreach ($translations as $key => $val) {
+ $translation_ids[$lang_ids[$key]] = $val;
+ }
+
+ $return .= 'case "' . basename($filename, '.inc.php') . '": $translations = array(';
+ foreach ($translation_ids as $val) {
+ $return .= (is_array($val) ? "array('" . implode("', '", array_map('add_apo_slashes', $val)) . "')" : "'" . add_apo_slashes($val) . "'") . ", ";
+ }
+ $return .= "); break;\n";
}
return "switch (\$LANG) {\n$return}\n";
}
@@ -81,6 +104,8 @@ function php_shrink($input) {
$file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])(;\\s*\\?>)?~s", 'remove_lang', $file);
$file = str_replace("<?php switch_lang(); ?>\n", "", $file);
$file = str_replace('<?php echo $LANG; ?>', $_COOKIE["lang"], $file);
+} else {
+ $file = preg_replace_callback("~lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])~s", 'lang_ids', $file);
}
$file = preg_replace("~favicon\\.ico|default\\.css|(up|down|plus|minus)\\.gif~", '<?php echo preg_replace("~\\\\\\\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?file=\\0"; ?>', $file);
$file = str_replace("arrow.gif", '" . preg_replace("~\\\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?file=arrow.gif', $file);

0 comments on commit 4738060

Please sign in to comment.