Globalize $translations
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@216 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
57391acbca
commit
4eb07d7006
|
@ -37,7 +37,7 @@ error_reporting(E_ALL & ~E_NOTICE);
|
||||||
if ($_SERVER["argc"] > 1) {
|
if ($_SERVER["argc"] > 1) {
|
||||||
$_COOKIE["lang"] = $_SERVER["argv"][1];
|
$_COOKIE["lang"] = $_SERVER["argv"][1];
|
||||||
include "./lang.inc.php";
|
include "./lang.inc.php";
|
||||||
if ($_SERVER["argc"] != 2 || !in_array($_SERVER["argv"][1], lang())) {
|
if ($_SERVER["argc"] != 2 || !isset($translations[$_COOKIE["lang"]])) {
|
||||||
echo "Usage: php _compile.php [lang]\nPurpose: Compile phpMinAdmin[-lang].php from index.php.\n";
|
echo "Usage: php _compile.php [lang]\nPurpose: Compile phpMinAdmin[-lang].php from index.php.\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ $file = preg_replace_callback('~(<\\?php)?\\s*(include|require)(_once)? "([^"]*)
|
||||||
if ($_COOKIE["lang"]) {
|
if ($_COOKIE["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("<?php switch_lang(); ?>\n", "", $file);
|
$file = str_replace("<?php switch_lang(); ?>\n", "", $file);
|
||||||
$file = str_replace("<?php echo get_lang(); ?>", $_COOKIE["lang"], $file);
|
$file = str_replace('<?php echo $LANG; ?>', $_COOKIE["lang"], $file);
|
||||||
}
|
}
|
||||||
$file = str_replace("favicon.ico", '<?php echo preg_replace("~\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?favicon="; ?>', $file);
|
$file = str_replace("favicon.ico", '<?php echo preg_replace("~\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?favicon="; ?>', $file);
|
||||||
$file = str_replace("arrow.gif", '" . preg_replace("~\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?gif=arrow', $file);
|
$file = str_replace("arrow.gif", '" . preg_replace("~\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?gif=arrow', $file);
|
||||||
|
|
|
@ -13,7 +13,7 @@ foreach (glob("*.php") as $filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = file_get_contents("lang.inc.php");
|
$file = file_get_contents("lang.inc.php");
|
||||||
preg_match_all("~\n\t\t'(.*)' => array\\(\n(.*\n)\t\t\\)~sU", $file, $translations, PREG_OFFSET_CAPTURE);
|
preg_match_all("~\n\t'(.*)' => array\\(\n(.*\n)\t\\)~sU", $file, $translations, PREG_OFFSET_CAPTURE);
|
||||||
foreach (array_reverse($translations[2], true) as $key => $translation) {
|
foreach (array_reverse($translations[2], true) as $key => $translation) {
|
||||||
$messages = $messages_all;
|
$messages = $messages_all;
|
||||||
preg_match_all("~^(\\s*)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => .*[^,\n]),?~m", $translation[0], $matches, PREG_SET_ORDER);
|
preg_match_all("~^(\\s*)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => .*[^,\n]),?~m", $translation[0], $matches, PREG_SET_ORDER);
|
||||||
|
@ -28,9 +28,9 @@ foreach (array_reverse($translations[2], true) as $key => $translation) {
|
||||||
}
|
}
|
||||||
foreach($messages as $idf => $val) {
|
foreach($messages as $idf => $val) {
|
||||||
if ($val == "," && strpos($idf, "%d")) {
|
if ($val == "," && strpos($idf, "%d")) {
|
||||||
$s .= "\t\t\t$idf => array(),\n";
|
$s .= "\t\t$idf => array(),\n";
|
||||||
} elseif ($translations[1][$key][0] != 'en') {
|
} elseif ($translations[1][$key][0] != 'en') {
|
||||||
$s .= "\t\t\t$idf => '',\n";
|
$s .= "\t\t$idf => '',\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$file = substr_replace($file, $s, $translation[1], strlen($translation[0]));
|
$file = substr_replace($file, $s, $translation[1], strlen($translation[0]));
|
||||||
|
|
22
lang.inc.php
22
lang.inc.php
|
@ -1,7 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
function lang($idf = null, $number = null) {
|
static $translations = array(
|
||||||
global $LANG;
|
|
||||||
static $translations = array(
|
|
||||||
'en' => array(
|
'en' => array(
|
||||||
'Query executed OK, %d row(s) affected.' => array('Query executed OK, %d row affected.', 'Query executed OK, %d rows affected.'),
|
'Query executed OK, %d row(s) affected.' => array('Query executed OK, %d row affected.', 'Query executed OK, %d rows affected.'),
|
||||||
'%d byte(s)' => array('%d byte', '%d bytes'),
|
'%d byte(s)' => array('%d byte', '%d bytes'),
|
||||||
|
@ -144,12 +142,12 @@ function lang($idf = null, $number = null) {
|
||||||
'Alter function' => 'Změnit funkci',
|
'Alter function' => 'Změnit funkci',
|
||||||
'Alter procedure' => 'Změnit proceduru',
|
'Alter procedure' => 'Změnit proceduru',
|
||||||
'Unable to operate routine' => 'Nepořadilo se zpracovat proceduru',
|
'Unable to operate routine' => 'Nepořadilo se zpracovat proceduru',
|
||||||
'Return type' => 'Návratový typ',
|
'Return type' => '',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (!isset($idf)) {
|
|
||||||
return array_keys($translations);
|
function lang($idf, $number = null) {
|
||||||
}
|
global $LANG, $translations;
|
||||||
$translation = $translations[$LANG][$idf];
|
$translation = $translations[$LANG][$idf];
|
||||||
if ($number === false) { // used in _compile.php
|
if ($number === false) { // used in _compile.php
|
||||||
return ($translation ? $translation : $idf);
|
return ($translation ? $translation : $idf);
|
||||||
|
@ -169,9 +167,10 @@ function lang($idf = null, $number = null) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function switch_lang() {
|
function switch_lang() {
|
||||||
|
global $translations;
|
||||||
echo "<p>" . lang('Language') . ":";
|
echo "<p>" . lang('Language') . ":";
|
||||||
$base = preg_replace('~(\\?)lang=[^&]*&|[&?]lang=[^&]*~', '\\1', $_SERVER["REQUEST_URI"]);
|
$base = preg_replace('~(\\?)lang=[^&]*&|[&?]lang=[^&]*~', '\\1', $_SERVER["REQUEST_URI"]);
|
||||||
foreach (lang() as $lang) {
|
foreach ($translations as $lang => $val) {
|
||||||
echo ' <a href="' . htmlspecialchars($base . (strpos($base, "?") !== false ? "&" : "?")) . "lang=$lang\">$lang</a>";
|
echo ' <a href="' . htmlspecialchars($base . (strpos($base, "?") !== false ? "&" : "?")) . "lang=$lang\">$lang</a>";
|
||||||
}
|
}
|
||||||
echo "</p>\n";
|
echo "</p>\n";
|
||||||
|
@ -185,11 +184,10 @@ if (isset($_GET["lang"])) {
|
||||||
if (strlen($_COOKIE["lang"])) {
|
if (strlen($_COOKIE["lang"])) {
|
||||||
$LANG = $_COOKIE["lang"];
|
$LANG = $_COOKIE["lang"];
|
||||||
} else {
|
} else {
|
||||||
$langs = lang();
|
|
||||||
$LANG = preg_replace('~[,;].*~', '', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
|
$LANG = preg_replace('~[,;].*~', '', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
|
||||||
if (!in_array($LANG, $langs)) { //! try next languages
|
if (!isset($translations[$LANG])) { //! try next languages
|
||||||
$LANG = preg_replace('~-.*~', '', $LANG);
|
$LANG = preg_replace('~-.*~', '', $LANG);
|
||||||
if (!in_array($LANG, $langs)) {
|
if (!isset($translations[$LANG])) {
|
||||||
$LANG = "en";
|
$LANG = "en";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue