* @package Mammut\Locale */ /* $Id$ */ (defined('MAMMUT') && (basename(__FILE__) != basename($_SERVER['PHP_SELF']))) or die('ACCESS DENIED'); /** * Seaches for the best matching locale requested by the user agent. * * @since 1.1.0.0 * * @param string $uaPrefer * User agent preference string (usually $_SERVER['HTTP_ACCEPT_LANGUAGE']) * @param array $allowed * Allowed locales to use * @param string $default * Default locale */ function find_best_ua_locale($uaPrefer, array $allowed, $default = 'en') { $langu = explode(',', $uaPrefer); $langPrioTable = array(); foreach($langu as $l) { if(strpos($l, ';') !== false) { list($st, $prio) = explode(';', $l); $langPrioTable[str_replace('q=', '', $prio)] = strtolower(str_replace('-', '_', $st)); } else $langPrioTable['1.0'] = strtolower(str_replace('-', '_', $l)); } krsort($langPrioTable); $lang = $default; foreach($langPrioTable as $l) { if(in_array($l, $allowed)) { $lang = strtolower($l); break; } } return $lang; } /** * Starts capturing of a translation text/key */ function _trst() { ob_start(); } /** * Ends capturing of a translation text/key and returns the result * * @param array $values * a parameter array * @return string the translated text */ function _trend(\Mammut\Locale\iTranslate $locale, $values = []) { $st = ob_get_clean(); if (is_scalar($values)) $values = [$values]; return $locale->tr($st, $values); } /** * Ends capturing of a translation text/key and returns the result * * @param int $count * a number parameter * @return string the translated text */ function _trendn(\Mammut\Locale\iTranslate $locale, $count, $values = []) { $st = ob_get_clean(); return $locale->trn($st, $count); }