/** * Main function to detect and set the default language. * * // Set the language * $lang = I18n::initialize(); */ public static function initialize() { // Installed Locales self::$_languages = Config::get('site.installed_locales', array()); // Allow the user or browser to override the default locale $locale_override = Config::get('site.locale_override', FALSE); // 1. Check the session specific preference (cookie) $locale = I18n::cookieLocale(); // 2. Check the user's preference if (!$locale and ($locale_override == 'ALL' or $locale_override == 'USER')) { $locale = I18n::userLocale(); } // 3. Check the request client/browser's preference if (!$locale and ($locale_override == 'ALL' or $locale_override == 'CLIENT')) { $locale = I18n::requestLocale(); } // 4. Check the url preference and get the language from url if (!$locale and ($locale_override == 'ALL' or $locale_override == 'URL')) { $locale = I18n::urlLocale(); } // 5. Check the sub-domain preference and get the language form subdomain if (!$locale and ($locale_override == 'ALL' or $locale_override == 'DOMAIN')) { $locale = I18n::domainLocale(); } // 6. Default locale if (!$locale) { $locale = Config::get('site.locale', I18n::$default); } // Set the locale I18n::lang($locale); return I18n::$lang; }