From dcc850bf01460655e23e5a4599679853cc080228 Mon Sep 17 00:00:00 2001 From: Sergio Brighenti Date: Mon, 19 Nov 2018 19:45:52 +0100 Subject: [PATCH] Consistent html lang attribute (#2) --- app/Web/Lang.php | 8 ++++++-- bootstrap/app.php | 7 +------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/Web/Lang.php b/app/Web/Lang.php index 4cc746d..bbf8074 100644 --- a/app/Web/Lang.php +++ b/app/Web/Lang.php @@ -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 { diff --git a/bootstrap/app.php b/bootstrap/app.php index aa5ab2f..964256d 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -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'));