2016-07-25 14:14:04 +00:00
|
|
|
<?php
|
|
|
|
session_start();
|
|
|
|
header('Cache-control: private');
|
|
|
|
|
|
|
|
if (isset($_GET['lang'])) {
|
|
|
|
$langcode = $_GET['lang'];
|
|
|
|
|
|
|
|
$_SESSION['lang'] = $langcode;
|
|
|
|
|
|
|
|
setcookie('lang', $langcode, time() + (3600 * 24 * 60));
|
2016-10-30 03:04:51 +00:00
|
|
|
|
|
|
|
header("Location: {$_SERVER['PHP_SELF']}");
|
2016-07-25 14:14:04 +00:00
|
|
|
} else if (isset($_SESSION['lang'])) {
|
|
|
|
$langcode = $_SESSION['lang'];
|
|
|
|
} else if (isset($_COOKIE['lang'])) {
|
|
|
|
$langcode = $_COOKIE['lang'];
|
2016-10-31 02:18:46 +00:00
|
|
|
} else if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
2016-07-25 14:14:04 +00:00
|
|
|
$langcode = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
|
|
|
|
} else {
|
|
|
|
$langcode = "en";
|
|
|
|
}
|
|
|
|
|
2016-10-31 02:18:46 +00:00
|
|
|
if (!file_exists(getLanguagePath($langcode)))
|
2016-07-25 14:14:04 +00:00
|
|
|
$langcode = "en";
|
|
|
|
|
|
|
|
require_once getLanguagePath($langcode);
|
|
|
|
|
|
|
|
function getLanguagePath($langcode) {
|
|
|
|
return __DIR__ . '/../config/languages/lang.' . $langcode . '.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
function tl($pattern, $args = null) {
|
|
|
|
echo translate($pattern, $args);
|
|
|
|
}
|
|
|
|
|
|
|
|
function translate($pattern, $args = null) {
|
|
|
|
|
2016-10-31 02:18:46 +00:00
|
|
|
if (!$args) {
|
2016-07-25 14:14:04 +00:00
|
|
|
return $pattern;
|
|
|
|
}
|
|
|
|
|
|
|
|
$size = count($args);
|
|
|
|
|
|
|
|
for ($i = 0; $i < $size; $i++) {
|
|
|
|
$pattern = str_ireplace('{' . $i . '}', $args[$i], $pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $pattern;
|
|
|
|
}
|