diff --git a/_compile.php b/_compile.php index 5be824ee..627e78b8 100644 --- a/_compile.php +++ b/_compile.php @@ -1,11 +1,25 @@ "'", "\\\\" => "\\"))); - return ($match[1] && $match[3] ? $s : "$match[1]'" . addcslashes($s, "\\'") . "'$match[3]"); + $s = lang(strtr($match[2], array("\\'" => "'", "\\\\" => "\\")), false); + if ($match[3] == ",") { + return "$match[1]" . (is_array($s) ? "lang(array('" . implode("', '", array_map('add_apo_slashes', $s)) . "')," : "sprintf('" . add_apo_slashes($s) . "',"); + } + return ($match[1] && $match[4] ? $s : "$match[1]'" . add_apo_slashes($s) . "'$match[4]"); } function put_file($match) { $return = file_get_contents($match[4]); + if ($match[4] == "./lang.inc.php") { + if (!$_SESSION["lang"]) { + $return = str_replace("\tif (\$number === false && \$translation) {\n\t\treturn \$translation; // used in _compile.php\n\t}\n", "", $return); + } elseif (preg_match("~case '$_SESSION[lang]': (.*) break;~", $return, $match) || preg_match("~default: (.*)~", $return, $match)) { + return "$match[1]\nfunction lang(\$ar, \$number) {\n\t$match[1]\n\treturn \$ar[\$pos];\n}\n$match[5]"; + } + } $return = preg_replace("~\\?>\n?\$~", '', $return); if (substr_count($return, "") && !$match[5]) { $return .= ")?~', 'put_file', $file); if ($_SESSION["lang"]) { - $file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']*|\\\\.)+)'\\)(;\\s*\\?>)?~s", 'remove_lang', $file); + $file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']*|\\\\.)+)'([,)])(;\\s*\\?>)?~s", 'remove_lang', $file); $file = str_replace("\n", "", $file); $file = str_replace("", $_SESSION["lang"], $file); } diff --git a/_lang.php b/_lang.php index f82324cb..45a4c1ab 100644 --- a/_lang.php +++ b/_lang.php @@ -7,8 +7,9 @@ if ($_SERVER["argc"] > 1) { $messages_all = array(); foreach (glob("*.php") as $filename) { $file = file_get_contents($filename); - preg_match_all("~lang\\(('(?:[^\\\\']*|\\\\.)+')[),]~s", $file, $matches); - $messages_all += array_flip($matches[1]); + if (preg_match_all("~lang\\(('(?:[^\\\\']*|\\\\.)+')([),])~", $file, $matches)) { + $messages_all += array_combine($matches[1], $matches[2]); + } } $file = file_get_contents("lang.inc.php"); @@ -25,9 +26,11 @@ foreach (array_reverse($translations[2], true) as $key => $translation) { $s .= "$match[1]// $match[2],\n"; } } - if ($translations[1][$key][0] != 'en') { - foreach($messages as $key => $val) { - $s .= "\t\t\t$key => '',\n"; + foreach($messages as $idf => $val) { + if ($val == ",") { + $s .= "\t\t\t$idf => array(),\n"; + } elseif ($translations[1][$key][0] != 'en') { + $s .= "\t\t\t$idf => '',\n"; } } $file = substr_replace($file, $s, $translation[1], strlen($translation[0])); diff --git a/design.inc.php b/design.inc.php index 91cf1d7c..99d6c784 100644 --- a/design.inc.php +++ b/design.inc.php @@ -1,9 +1,10 @@ - +