本文整理汇总了PHP中Fuel::locale方法的典型用法代码示例。如果您正苦于以下问题:PHP Fuel::locale方法的具体用法?PHP Fuel::locale怎么用?PHP Fuel::locale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fuel
的用法示例。
在下文中一共展示了Fuel::locale方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: lang
/**
* Gets the current language from either TLD, URL prefix or
*/
public static function lang()
{
if (static::$lang !== null) {
return static::$lang;
}
// Give up if we haven't enabled multi lingual
if (!(static::$lang_enabled = \Config::get('cmf.languages.enabled', false))) {
return static::$lang = \Lang::get_lang();
}
// First load our languages
\Lang::load('languages', true);
// Get the language from cookies
$iso = \Cookie::get('default_language');
$fallback = \Lang::get_lang();
// Get the language from URL
if (!$iso) {
$languages = static::languages();
$host = preg_replace("/^www\\./i", '', strtolower(\Input::server('HTTP_HOST', '')));
foreach ($languages as $language) {
if ($tld = \Arr::get($language, 'top_level_domain')) {
$parts = array_filter(array_map(function ($part) {
return preg_replace("/^www\\./i", '', strtolower(trim($part)));
}, explode(',', $tld)));
if (in_array($host, $parts)) {
$iso = $language['code'];
break;
}
}
}
}
// Get the language from the request
if (!$iso) {
$iso = strtolower(\Arr::get(explode('/', static::original_uri()), 1, \Lang::get_lang()) . "");
if (strpos($iso, '_') !== false) {
$parts = explode('_', $iso);
$iso = strtolower($parts[0]) . '_' . strtoupper($parts[1]);
}
if (\Lang::_get("languages.{$iso}", array(), 'notfound') == 'notfound') {
$iso = \Lang::get_lang();
}
}
// Set the languages into Fuel for future reference
\Config::set('language_fallback', $fallback);
\Config::set('language', $iso);
\CMF\Doctrine\Extensions\Translatable::setLang($iso);
// Load the languages back in, now we might have a translation for them
if ($fallback != $iso) {
\Lang::load('errors', true, $iso, false, true);
\Lang::load('languages', true, $iso, false, true);
\Lang::load('admin', true, $iso, false, true);
\Lang::load('site', true, $iso, false, true);
static::$lang_prefix = "/{$iso}";
}
// Set the uri filter so we don't see the lang prefix
\Config::set('security.uri_filter', array_merge(array('\\CMF::removeLangPrefix'), \Config::get('security.uri_filter')));
// Log to console
if (\Fuel::$profiling) {
\Profiler::console('Language is ' . $iso);
}
// Add shutdown event to catch unsaved translation strings
\Event::register('shutdown', 'Lang::shutdown');
// Set the lang vars
static::$lang_default = $fallback;
static::$lang = $iso;
// Set locale if necessary
if (is_array($locale_map = \Config::get('locale_map')) && ($new_locale = \Arr::get($locale_map, $iso))) {
$result = setlocale(LC_TIME, $new_locale);
if ($result !== false) {
\Fuel::$locale = $result;
\Config::set('locale', $result);
if (class_exists('Locale')) {
\Locale::setDefault($result);
}
}
}
// Redirect to default language if this one isn't configured
if (!array_key_exists($iso, static::languages()) && array_key_exists($fallback, static::languages())) {
\Response::redirect(static::link(\Input::uri(), $fallback));
}
return $iso;
}