瀏覽代碼

Consistent html lang attribute (#2)

Sergio Brighenti 6 年之前
父節點
當前提交
dcc850bf01
共有 2 個文件被更改,包括 7 次插入8 次删除
  1. 6 2
      app/Web/Lang.php
  2. 1 6
      bootstrap/app.php

+ 6 - 2
app/Web/Lang.php

@@ -58,7 +58,11 @@ class Lang
 			$lang = strtolower(substr($lang, 0, 2));
 			$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;
 		return self::$instance;
 	}
 	}
@@ -85,7 +89,7 @@ class Lang
 
 
 		if (array_key_exists($lang, $this->cache)) {
 		if (array_key_exists($lang, $this->cache)) {
 			$transDict = $this->cache[$lang];
 			$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';
 			$transDict = include $this->path . $lang . '.lang.php';
 			$this->cache[$lang] = $transDict;
 			$this->cache[$lang] = $transDict;
 		} else {
 		} else {

+ 1 - 6
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/');
 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) {
 $container['view'] = function ($container) use (&$config) {
 	$view = new \Slim\Views\Twig(__DIR__ . '/../resources/templates', [
 	$view = new \Slim\Views\Twig(__DIR__ . '/../resources/templates', [
 		'cache' => __DIR__ . '/../resources/cache',
 		'cache' => __DIR__ . '/../resources/cache',
@@ -82,7 +77,7 @@ $container['view'] = function ($container) use (&$config) {
 	$view->getEnvironment()->addGlobal('request', $container->get('request'));
 	$view->getEnvironment()->addGlobal('request', $container->get('request'));
 	$view->getEnvironment()->addGlobal('alerts', Session::getAlert());
 	$view->getEnvironment()->addGlobal('alerts', Session::getAlert());
 	$view->getEnvironment()->addGlobal('session', Session::all());
 	$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()->addGlobal('PLATFORM_VERSION', PLATFORM_VERSION);
 
 
 	$view->getEnvironment()->addFunction(new Twig_Function('route', 'route'));
 	$view->getEnvironment()->addFunction(new Twig_Function('route', 'route'));