2007-07-05 05:41:18 +00:00
|
|
|
<?php
|
2008-07-10 15:39:24 +00:00
|
|
|
$langs = array(
|
2007-08-04 19:36:22 +00:00
|
|
|
'en' => 'English',
|
|
|
|
'cs' => 'Čeština', // Jakub Vrána - http://php.vrana.cz
|
|
|
|
'sk' => 'Slovenčina', // Ivan Suchy - http://www.ivansuchy.com
|
2008-01-08 14:01:29 +00:00
|
|
|
'nl' => 'Nederlands', // Maarten Balliauw - http://blog.maartenballiauw.be
|
2008-05-07 07:49:59 +00:00
|
|
|
'es' => 'Español', // Klemens Häckel - http://clickdimension.wordpress.com
|
2008-05-15 14:38:15 +00:00
|
|
|
'de' => 'Deutsch', // Klemens Häckel - http://clickdimension.wordpress.com
|
2008-08-07 08:53:09 +00:00
|
|
|
'zh' => '简体中文', // Mr. Lodar
|
2008-08-22 11:34:50 +00:00
|
|
|
'fr' => 'Français', // Francis Gagné
|
2008-08-29 14:16:16 +00:00
|
|
|
'it' => 'Italiano', // SF.net ticket #2082471
|
2007-07-17 14:04:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
function lang($idf, $number = null) {
|
|
|
|
global $LANG, $translations;
|
2007-08-04 19:36:22 +00:00
|
|
|
$translation = $translations[$idf];
|
2007-07-09 15:28:37 +00:00
|
|
|
if (is_array($translation) && $translation) {
|
2008-07-09 04:18:21 +00:00
|
|
|
$pos = ($number == 1 ? 0 : 1);
|
2007-07-09 15:28:37 +00:00
|
|
|
switch ($LANG) {
|
|
|
|
case 'cs': $pos = ($number == 1 ? 0 : (!$number || $number >= 5 ? 2 : 1)); break;
|
2007-07-27 09:12:57 +00:00
|
|
|
case 'sk': $pos = ($number == 1 ? 0 : (!$number || $number >= 5 ? 2 : 1)); break;
|
2007-07-05 10:46:44 +00:00
|
|
|
}
|
2007-07-09 06:12:22 +00:00
|
|
|
$translation = $translation[$pos];
|
2007-07-05 10:46:44 +00:00
|
|
|
}
|
2007-07-25 10:19:00 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
array_shift($args);
|
|
|
|
return vsprintf(($translation ? $translation : $idf), $args);
|
2007-07-05 10:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function switch_lang() {
|
2007-08-04 19:36:22 +00:00
|
|
|
global $langs;
|
2007-08-09 15:00:48 +00:00
|
|
|
echo "<p id='lang'>" . lang('Language') . ":";
|
2007-07-27 11:43:44 +00:00
|
|
|
$base = remove_from_uri("lang");
|
2007-08-04 19:36:22 +00:00
|
|
|
foreach ($langs as $lang => $val) {
|
|
|
|
echo ' <a href="' . htmlspecialchars($base . (strpos($base, "?") !== false ? "&" : "?")) . "lang=$lang\" title='$val'>$lang</a>";
|
2007-07-05 10:46:44 +00:00
|
|
|
}
|
|
|
|
echo "</p>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_GET["lang"])) {
|
2007-07-13 14:37:23 +00:00
|
|
|
$_COOKIE["lang"] = $_GET["lang"];
|
2007-07-27 11:43:01 +00:00
|
|
|
$_SESSION["lang"] = $_GET["lang"];
|
2007-07-05 05:41:18 +00:00
|
|
|
}
|
2007-07-09 15:28:37 +00:00
|
|
|
|
2008-07-10 15:39:24 +00:00
|
|
|
$LANG = "en";
|
2007-08-04 19:36:22 +00:00
|
|
|
if (isset($langs[$_COOKIE["lang"]])) {
|
|
|
|
setcookie("lang", $_GET["lang"], strtotime("+1 month"), preg_replace('~\\?.*~', '', $_SERVER["REQUEST_URI"]));
|
2007-07-13 14:37:23 +00:00
|
|
|
$LANG = $_COOKIE["lang"];
|
2007-08-04 19:36:22 +00:00
|
|
|
} elseif (isset($langs[$_SESSION["lang"]])) {
|
2007-07-27 11:43:01 +00:00
|
|
|
$LANG = $_SESSION["lang"];
|
2007-07-09 15:28:37 +00:00
|
|
|
} else {
|
2007-07-25 11:19:40 +00:00
|
|
|
$accept_language = array();
|
2007-08-07 12:50:08 +00:00
|
|
|
preg_match_all('~([-a-z_]+)(;q=([0-9.]+))?~', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]), $matches, PREG_SET_ORDER);
|
2007-07-25 11:19:40 +00:00
|
|
|
foreach ($matches as $match) {
|
2007-08-07 12:50:08 +00:00
|
|
|
$accept_language[str_replace("_", "-", $match[1])] = (isset($match[3]) ? $match[3] : 1);
|
2007-07-25 11:19:40 +00:00
|
|
|
}
|
|
|
|
arsort($accept_language);
|
|
|
|
foreach ($accept_language as $lang => $q) {
|
2007-08-04 19:36:22 +00:00
|
|
|
if (isset($langs[$lang])) {
|
2007-07-25 11:19:40 +00:00
|
|
|
$LANG = $lang;
|
|
|
|
break;
|
|
|
|
}
|
2007-08-07 12:57:10 +00:00
|
|
|
$lang = preg_replace('~-.*~', '', $lang);
|
2007-08-04 19:36:22 +00:00
|
|
|
if (!isset($accept_language[$lang]) && isset($langs[$lang])) {
|
2007-07-25 11:19:40 +00:00
|
|
|
$LANG = $lang;
|
|
|
|
break;
|
2007-07-09 15:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|