/** * Returns the preferred section based on session, cookie, * user object, default browser (if allowed), and finally * site preferences. * Since the user's language is not a locale but a language, * attempts to determine best section for the given language. * * @return Section */ public static function getPreferredSection() { $site = \Site::getSite(); $locale = false; $app = Facade::getFacadeApplication(); // they have a language in a certain session going already $session = $app->make('session'); if ($session->has('multilingual_default_locale')) { $locale = $session->get('multilingual_default_locale'); } else { $cookie = $app->make('cookie'); if ($cookie->has('multilingual_default_locale')) { $locale = $cookie->get('multilingual_default_locale'); } } if ($locale) { $home = Section::getByLocale($locale); if ($home) { return $home; } } $u = new \User(); if ($u->isRegistered()) { $userDefaultLanguage = $u->getUserDefaultLanguage(); if ($userDefaultLanguage) { $home = Section::getByLocaleOrLanguage($userDefaultLanguage); if ($home) { return $home; } } } $config = $site->getConfigRepository(); if ($config->get('multilingual.use_browser_detected_locale')) { $home = false; $locales = \Punic\Misc::getBrowserLocales(); foreach (array_keys($locales) as $locale) { $home = Section::getByLocaleOrLanguage($locale); if ($home) { break; } } if ($home) { return $home; } } $site = \Site::getSite(); return Section::getByLocale($site->getDefaultLocale()); }
/** * * Returns the preferred section based on session, cookie, * user object, default browser (if allowed), and finally * site preferences. * Since the user's language is not a locale but a language, * attempts to determine best section for the given language. * @return Section */ public static function getPreferredSection() { $locale = false; // they have a language in a certain session going already if (Session::has('multilingual_default_locale')) { $locale = Session::get('multilingual_default_locale'); } else { if (Cookie::has('multilingual_default_locale')) { $locale = Cookie::get('multilingual_default_locale'); } } if ($locale) { $home = Section::getByLocale($locale); if ($home) { return $home; } } $u = new \User(); if ($u->isRegistered()) { $userDefaultLanguage = $u->getUserDefaultLanguage(); if ($userDefaultLanguage) { $home = Section::getByLocaleOrLanguage($userDefaultLanguage); if ($home) { return $home; } } } if (Config::get('concrete.multilingual.use_browser_detected_locale')) { $home = false; $locales = \Punic\Misc::getBrowserLocales(); foreach (array_keys($locales) as $locale) { $home = Section::getByLocaleOrLanguage($locale); if ($home) { break; } } if ($home) { return $home; } } return Section::getByLocale(Config::get('concrete.multilingual.default_locale')); }
public function getSessionDefaultLocale() { // they have a language in a certain session going already if (isset($_SESSION['DEFAULT_LOCALE'])) { return $_SESSION['DEFAULT_LOCALE']; } // if they've specified their own default locale to remember if (isset($_COOKIE['DEFAULT_LOCALE'])) { return $_COOKIE['DEFAULT_LOCALE']; } if (User::isLoggedIn()) { $u = new User(); $userDefaultLanguage = $u->getUserDefaultLanguage(); if ($userDefaultLanguage != '') { if (is_object(MultilingualSection::getByLocale($userDefaultLanguage)) || $userDefaultLanguage == 'en_US' && Page::getCurrentPage()->cID != 1) { return $userDefaultLanguage; } } } $pkg = Package::getByHandle('multilingual'); // // This could set the cookie here but it does not. // If something wants to set the default language it should probably do that outside of here. // if ($pkg->config('TRY_BROWSER_LANGUAGE')) { Loader::model('section', 'multilingual'); Loader::library('3rdparty/Zend/Locale'); $locale = new Zend_Locale(); if (is_object(MultilingualSection::getByLocale((string) $locale))) { return (string) $locale; } else { $section = MultilingualSection::getByLanguage((string) $locale->getLanguage()); if (is_object($section)) { return (string) $section->getLocale(); } } } return $pkg->config('DEFAULT_LANGUAGE'); }
<? defined('C5_EXECUTE') or die("Access Denied."); $u = new User(); Config::getOrDefine('SITE_LOCALE', 'en_US'); if ($u->getUserDefaultLanguage() != '') { define('ACTIVE_LOCALE', $u->getUserDefaultLanguage()); } else if (defined('LOCALE')) { define('ACTIVE_LOCALE', LOCALE); } else { define('ACTIVE_LOCALE', SITE_LOCALE); } if (strpos(ACTIVE_LOCALE, '_') > -1) { $loc = explode('_', ACTIVE_LOCALE); if (is_array($loc) && count($loc) == 2) { define('LANGUAGE', $loc[0]); } } define('DIRNAME_LANGUAGES_SITE_INTERFACE', 'site'); if (!defined('DIR_LANGUAGES_SITE_INTERFACE')) { define('DIR_LANGUAGES_SITE_INTERFACE', DIR_LANGUAGES . '/' . DIRNAME_LANGUAGES_SITE_INTERFACE); } if (!defined('REL_DIR_LANGUAGES_SITE_INTERFACE')) { define('REL_DIR_LANGUAGES_SITE_INTERFACE', DIR_REL . '/' . DIRNAME_LANGUAGES . '/' . DIRNAME_LANGUAGES_SITE_INTERFACE); }