本文整理汇总了PHP中TTi18n::getLocaleCookie方法的典型用法代码示例。如果您正苦于以下问题:PHP TTi18n::getLocaleCookie方法的具体用法?PHP TTi18n::getLocaleCookie怎么用?PHP TTi18n::getLocaleCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TTi18n
的用法示例。
在下文中一共展示了TTi18n::getLocaleCookie方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: chooseBestLocale
/**
* Determines the most appropriate locale, based on user metadata including
* the user's saved locale preference (if any), the user's browser lang pref,
* and the application's default locale. It also allows an override via
* setting URL param 'ttlang' to a valid locale.
*
* Returns the best locale, or false if unable to find and set a locale.
*
* @param string|array $user_locale_pref
* @return string|boolean
* @author Dan Libby <dan@osc.co.cr>
*/
public static function chooseBestLocale($user_locale_pref = NULL)
{
Debug::text('Choosing Best Locale...', __FILE__, __LINE__, __METHOD__, 10);
$success = FALSE;
$category = LC_ALL;
//LC_MESSAGES isn't defined on Windows.
// First, we'll check if 'ttlang' url param (override) is specified.
//Check cookie first, as we want GET/POST to override the cookie, incase of form errors on Login page etc...
if (TTi18n::getLocaleCookie() != FALSE) {
Debug::text('Using Language from cookie: ' . TTi18n::getLocaleCookie(), __FILE__, __LINE__, __METHOD__, 10);
$success = TTi18n::setLocale(TTi18n::getLocaleCookie(), $category);
}
if (isset($_GET['language']) and $_GET['language'] != '') {
Debug::text('Using Language from _GET: ' . $_GET['language'], __FILE__, __LINE__, __METHOD__, 10);
$success = self::setLocale($_GET['language']);
}
if (isset($_POST['language']) and $_POST['language'] != '') {
Debug::text('Using Language from _POST: ' . $_POST['language'], __FILE__, __LINE__, __METHOD__, 10);
$success = self::setLocale($_POST['language']);
}
if ($success == FALSE) {
// Check for a user pref first.
if ($user_locale_pref != '') {
// Could be an array of preferred locales.
if (is_array($user_locale_pref)) {
foreach ($user_locale_pref as $locale) {
Debug::text('aSetting Locale: ' . $user_locale_pref, __FILE__, __LINE__, __METHOD__, 10);
if ($success = self::setLocale($locale, $category)) {
break;
}
}
} else {
Debug::text('bSetting Locale: ' . $user_locale_pref, __FILE__, __LINE__, __METHOD__, 10);
// or a single locale
$success = self::setLocale($user_locale_pref, $category);
}
}
}
// Otherwise, check for lang prefs from the browser
if ($success == FALSE) {
// browser can specify more than one, so we get an array.
$browser_lang_prefs = self::getBrowserLanguage();
foreach ($browser_lang_prefs as $locale) {
//The country code needs to be upper case for locales to work correctly.
if (strpos($locale, '_') !== FALSE) {
$split_locale = explode('_', $locale);
if (isset($split_locale[1])) {
$locale = $split_locale[0] . '_' . strtoupper($split_locale[1]);
}
}
Debug::text('cSetting Locale: ' . $locale, __FILE__, __LINE__, __METHOD__, 10);
if ($success = self::setLocale($locale, $category)) {
break;
}
}
}
if ($success == FALSE) {
global $config_vars;
//Use system locale if its set from timetrex.ini.php
if (isset($config_vars['other']['system_locale']) and $config_vars['other']['system_locale'] != '') {
Debug::text('Using system locale from .ini: ' . $config_vars['other']['system_locale'], __FILE__, __LINE__, __METHOD__, 10);
$success = self::setLocale($config_vars['other']['system_locale'], $category);
}
}
// If it worked, then we save this for future reference.
if ($success !== FALSE) {
Debug::text('Using Locale: ' . self::getLocale(), __FILE__, __LINE__, __METHOD__, 10);
} else {
Debug::text('Unable to find and set a locale.', __FILE__, __LINE__, __METHOD__, 10);
}
return TRUE;
}
示例2:
$db_time_zone_error = TRUE;
}
/*
* Check locale cookie, if it varies from UserPreference Language,
* change user preferences to match. This could cause some unexpected behavior
* as the change is happening behind the scenes, but if we don't change
* the user prefs then they could login for weeks/months as a different
* language from their preferences, therefore making the user preference
* setting almost useless. Causing issues when printing pay stubs and in each
* users language.
*/
$profiler->startTimer("setLocale()");
Debug::text('Locale Cookie: ' . TTi18n::getLocaleCookie(), __FILE__, __LINE__, __METHOD__, 10);
if (TTi18n::getLocaleCookie() != '' and $current_user_prefs->getLanguage() !== TTi18n::getLanguageFromLocale(TTi18n::getLocaleCookie())) {
Debug::text('Changing User Preference Language to match cookie...', __FILE__, __LINE__, __METHOD__, 10);
$current_user_prefs->setLanguage(TTi18n::getLanguageFromLocale(TTi18n::getLocaleCookie()));
if ($current_user_prefs->isValid()) {
$current_user_prefs->Save(FALSE);
}
} else {
Debug::text('User Preference Language matches cookie!', __FILE__, __LINE__, __METHOD__, 10);
}
if (isset($_GET['language']) and $_GET['language'] != '') {
TTi18n::setLocale($_GET['language']);
//Sets master locale
} else {
TTi18n::setLanguage($current_user_prefs->getLanguage());
TTi18n::setCountry($current_user->getCountry());
TTi18n::setLocale();
//Sets master locale
}
示例3: getPreLoginData
function getPreLoginData($api = NULL)
{
global $config_vars;
return array('primary_company_id' => PRIMARY_COMPANY_ID, 'base_url' => Environment::getBaseURL(), 'api_url' => Environment::getAPIURL($api), 'api_base_url' => Environment::getAPIBaseURL($api), 'api_json_url' => Environment::getAPIURL('json'), 'images_url' => Environment::getImagesURL(), 'powered_by_logo_enabled' => $this->isPoweredByLogoEnabled(), 'product_edition' => $this->getTTProductEdition(FALSE), 'product_edition_name' => $this->getTTProductEdition(TRUE), 'deployment_on_demand' => $this->getDeploymentOnDemand(), 'web_session_expire' => (isset($config_vars['other']['web_session_expire']) and $config_vars['other']['web_session_expire'] != '') ? (bool) $config_vars['other']['web_session_expire'] : FALSE, 'analytics_enabled' => $this->isAnalyticsEnabled(), 'registration_key' => $this->getRegistrationKey(), 'http_host' => $this->getHTTPHost(), 'application_version' => $this->getApplicationVersion(), 'is_logged_in' => $this->isLoggedIn(), 'language_options' => Misc::addSortPrefix(TTi18n::getLanguageArray()), 'language' => TTi18n::getLanguageFromLocale(TTi18n::getLocaleCookie()));
}