' . money_format('%.2n', $amount) . ''; } public static function formatCredits($amount) { return '' . (is_numeric($amount) ? number_format($amount, 1) : $amount) . ' LBC'; } public static function translate($token, $language = null) { $language = $language === null ? static::$language : $language; 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) { if (isset($scope[$level])) { $scope = $scope[$level]; } else { $scope = []; } } if (!$scope && $language != 'en') { return static::translate($token, 'en'); } return $scope ?: $token; } protected static function deduceCulture() { $candidates = []; //url trumps everything $urlTokens = Request::getHost() ? explode('.', Request::getHost()) : []; $code = $urlTokens ? reset($urlTokens) : null; if ($code !== 'www') { $candidates[] = $code; } //then session $candidates[] = Session::get(Session::KEY_USER_CULTURE); // then headers // http://www.thefutureoftheweb.com/blog/use-accept-language-header 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', Request::getHttpHeader('Accept-Language'), $languages); if (isset($languages[1]) && count($languages[1])) { // create a list like "en" => 0.8 $langs = array_combine($languages[1], $languages[4]); // set default to 1 for any without q factor foreach ($langs as $lang => $val) { if ($val === '') { $langs[$lang] = 1; } } arsort($langs, SORT_NUMERIC); $candidates = array_merge($candidates, array_keys($langs)); } } foreach ($candidates as $candidate) { foreach (static::getAllCultures() as $culture) { if ($candidate === $culture || substr($culture, 0, 2) === $candidate) { return $culture; } } } return 'en_US'; } }