Language selection

Better way to select language
master
Dennis Neufeld 2017-05-16 18:11:58 +02:00
parent 4a9c9c220a
commit 8fb6a4c34d
2 changed files with 22 additions and 63 deletions

View File

@ -2,8 +2,8 @@
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/sessions.inc.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/sessions.inc.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/vars.inc.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/vars.inc.php';
if (file_exists('./inc/vars.local.inc.php')) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/inc/vars.local.inc.php')) {
include_once 'inc/vars.local.inc.php'; include_once $_SERVER['DOCUMENT_ROOT'] . '/inc/vars.local.inc.php';
} }
// Yubi OTP API // Yubi OTP API
@ -32,13 +32,13 @@ $offset = sprintf('%+d:%02d', $hrs*$sgn, $mins);
$dsn = $database_type . ":host=" . $database_host . ";dbname=" . $database_name; $dsn = $database_type . ":host=" . $database_host . ";dbname=" . $database_name;
$opt = [ $opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_EMULATE_PREPARES => false,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET time_zone = '" . $offset . "'", PDO::MYSQL_ATTR_INIT_COMMAND => "SET time_zone = '" . $offset . "'",
]; ];
try { try {
$pdo = new PDO($dsn, $database_user, $database_pass, $opt); $pdo = new PDO($dsn, $database_user, $database_pass, $opt);
} }
catch (PDOException $e) { catch (PDOException $e) {
?> ?>
@ -47,64 +47,20 @@ catch (PDOException $e) {
exit; exit;
} }
// Set language
$_SESSION['mailcow_locale'] = strtolower(trim($DEFAULT_LANG)); $_SESSION['mailcow_locale'] = strtolower(trim($DEFAULT_LANG));
setcookie('language', $DEFAULT_LANG);
if (isset($_COOKIE['language'])) { if (isset($_GET['lang']) && in_array($_GET['lang'], $AVAILABLE_LANGUAGES)) {
switch ($_COOKIE['language']) { $_SESSION['mailcow_locale'] = $_GET['lang'];
case "de":
$_SESSION['mailcow_locale'] = 'de';
setcookie('language', 'de');
break;
case "en":
$_SESSION['mailcow_locale'] = 'en';
setcookie('language', 'en');
break;
case "es":
$_SESSION['mailcow_locale'] = 'es';
setcookie('language', 'es');
break;
case "nl":
$_SESSION['mailcow_locale'] = 'nl';
setcookie('language', 'nl');
break;
case "pt":
$_SESSION['mailcow_locale'] = 'pt';
setcookie('language', 'pt');
break;
case "ru":
$_SESSION['mailcow_locale'] = 'ru';
setcookie('language', 'ru');
break;
}
} }
if (isset($_GET['lang'])) { elseif (isset($_COOKIE['language']) && in_array($_COOKIE['language'], $AVAILABLE_LANGUAGES)) {
switch ($_GET['lang']) { $_SESSION['mailcow_locale'] = $_COOKIE['language'];
case "de":
$_SESSION['mailcow_locale'] = 'de';
setcookie('language', 'de');
break;
case "en":
$_SESSION['mailcow_locale'] = 'en';
setcookie('language', 'en');
break;
case "es":
$_SESSION['mailcow_locale'] = 'es';
setcookie('language', 'es');
break;
case "nl":
$_SESSION['mailcow_locale'] = 'nl';
setcookie('language', 'nl');
break;
case "pt":
$_SESSION['mailcow_locale'] = 'pt';
setcookie('language', 'pt');
break;
case "ru":
$_SESSION['mailcow_locale'] = 'ru';
setcookie('language', 'ru');
break;
}
} }
if (isset($_SESSION['mailcow_locale']) && file_exists($_SERVER['DOCUMENT_ROOT'] . '/lang/lang.'.$_SESSION['mailcow_locale'].'.php')) {
$_SESSION['mailcow_locale'] = strtolower(trim($DEFAULT_LANG));
}
setcookie('language', $_SESSION['mailcow_locale']);
require_once $_SERVER['DOCUMENT_ROOT'] . '/lang/lang.en.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/lang/lang.en.php';
include $_SERVER['DOCUMENT_ROOT'] . '/lang/lang.'.$_SESSION['mailcow_locale'].'.php'; include $_SERVER['DOCUMENT_ROOT'] . '/lang/lang.'.$_SESSION['mailcow_locale'].'.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.inc.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.inc.php';

View File

@ -27,9 +27,12 @@ $FORM_ACTION = "previous";
$MC_DKIM_TXTS = "/data/dkim/txt"; $MC_DKIM_TXTS = "/data/dkim/txt";
$MC_DKIM_KEYS = "/data/dkim/keys"; $MC_DKIM_KEYS = "/data/dkim/keys";
// Change default language, "en", "es" "pt", "de", "ru" or "nl" // Change default language, "de", "en", "es", "nl", "pt", "ru"
$DEFAULT_LANG = "en"; $DEFAULT_LANG = "en";
// Available languages
$AVAILABLE_LANGUAGES = array("de", "en", "es", "nl", "pt", "ru");
// Change theme (default: lumen) // Change theme (default: lumen)
// Needs to be one of those: cerulean, cosmo, cyborg, darkly, flatly, journal, lumen, paper, readable, sandstone, // Needs to be one of those: cerulean, cosmo, cyborg, darkly, flatly, journal, lumen, paper, readable, sandstone,
// simplex, slate, spacelab, superhero, united, yeti // simplex, slate, spacelab, superhero, united, yeti