Consistent html lang attribute (#2)

This commit is contained in:
Sergio Brighenti 2018-11-19 19:45:52 +01:00
parent deab83f737
commit dcc850bf01
2 changed files with 7 additions and 8 deletions

View file

@ -58,7 +58,11 @@ class Lang
$lang = strtolower(substr($lang, 0, 2));
}
self::$instance = new self($lang, $path);
if (file_exists(($path ? $path : self::LANG_PATH) . $lang . '.lang.php')) {
self::$instance = new self($lang, $path);
} else {
self::$instance = new self(self::DEFAULT_LANG, $path);
}
return self::$instance;
}
@ -85,7 +89,7 @@ class Lang
if (array_key_exists($lang, $this->cache)) {
$transDict = $this->cache[$lang];
} elseif (file_exists($this->path . $lang . '.lang.php')) {
} else if (file_exists($this->path . $lang . '.lang.php')) {
$transDict = include $this->path . $lang . '.lang.php';
$this->cache[$lang] = $transDict;
} else {

View file

@ -60,11 +60,6 @@ $container['database'] = function ($container) use (&$config) {
Lang::build(substr(@$_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2), __DIR__. '/../resources/lang/');
$container['lang'] = function ($container) {
return Lang::getInstance();
};
$container['view'] = function ($container) use (&$config) {
$view = new \Slim\Views\Twig(__DIR__ . '/../resources/templates', [
'cache' => __DIR__ . '/../resources/cache',
@ -82,7 +77,7 @@ $container['view'] = function ($container) use (&$config) {
$view->getEnvironment()->addGlobal('request', $container->get('request'));
$view->getEnvironment()->addGlobal('alerts', Session::getAlert());
$view->getEnvironment()->addGlobal('session', Session::all());
$view->getEnvironment()->addGlobal('current_lang', $container->get('lang')->getLang());
$view->getEnvironment()->addGlobal('current_lang', Lang::getInstance()->getLang());
$view->getEnvironment()->addGlobal('PLATFORM_VERSION', PLATFORM_VERSION);
$view->getEnvironment()->addFunction(new Twig_Function('route', 'route'));