From 23e4e3c960762089f4e7b520d6c5d0d571b02739 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Tue, 20 Sep 2016 10:07:20 -0400 Subject: [PATCH] fixes --- lib/i18n.class.php | 21 +++++++++++---------- view/template/nav/_globalItems.php | 4 +++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/i18n.class.php b/lib/i18n.class.php index b02aaa52..482d0d67 100644 --- a/lib/i18n.class.php +++ b/lib/i18n.class.php @@ -22,7 +22,7 @@ class i18n list($language, $country) = explode('_', $culture); static::$language = $language; - static::$country = $country; + static::$country = $country; setlocale(LC_MONETARY, $culture . '.UTF-8'); } @@ -39,7 +39,7 @@ class i18n public static function getAllCultures() { - return static::$cultures; + return static::$cultures; } public static function formatCurrency($amount, $currency = 'USD') @@ -49,7 +49,7 @@ class i18n public static function formatCredits($amount) { - return '' . (is_numeric($amount) ? number_format($amount, 1) : $amount) . ' LBC'; + return '' . (is_numeric($amount) ? number_format($amount, 1) : $amount) . ' LBC'; } public static function translate($token, $language = null) @@ -58,10 +58,11 @@ class i18n if (!isset(static::$translations[$language])) { $path = ROOT_DIR . '/data/i18n/' . $language . '.yaml'; + static::$translations[$language] = file_exists($path) ? Spyc::YAMLLoadString(file_get_contents($path)) : []; } $scope = static::$translations[$language]; - foreach(explode('.', $token) as $level) + foreach (explode('.', $token) as $level) { if (isset($scope[$level])) { @@ -85,7 +86,7 @@ class i18n //url trumps everything $urlTokens = Request::getHost() ? explode('.', Request::getHost()) : []; - $code = $urlTokens ? reset($urlTokens) : null; + $code = $urlTokens ? reset($urlTokens) : null; if ($code !== 'www') { $candidates[] = $code; @@ -96,15 +97,15 @@ class i18n // then headers // http://www.thefutureoftheweb.com/blog/use-accept-language-header - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) + if (Request::getHttpHeader('Accept-Language')) { // break up string into pieces (languages and q factors) - preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse); + preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', Request::getHttpHeader('Accept-Language'), $languages); - if (count($lang_parse[1])) + if (isset($languages[1]) && count($languages[1])) { // create a list like "en" => 0.8 - $langs = array_combine($lang_parse[1], $lang_parse[4]); + $langs = array_combine($languages[1], $languages[4]); // set default to 1 for any without q factor foreach ($langs as $lang => $val) @@ -121,7 +122,7 @@ class i18n } } - foreach($candidates as $candidate) + foreach ($candidates as $candidate) { foreach (static::getAllCultures() as $culture) { diff --git a/view/template/nav/_globalItems.php b/view/template/nav/_globalItems.php index 9e27de83..2ef3791b 100644 --- a/view/template/nav/_globalItems.php +++ b/view/template/nav/_globalItems.php @@ -26,7 +26,9 @@