get_persist_locale() public static method

Gets the locale currently set within either the session or cookie.
public static get_persist_locale ( string $key = null ) : string | null
$key string ID to retrieve persistant locale from. Will automatically detect if omitted. Either Fluent::config()->persist_id or Fluent::config()->persist_id_cms.
return string | null The locale, if available
コード例 #1
0
 /**
  * For incoming traffic to the site root, determine if they should be redirected to any locale.
  *
  * @return string|null The locale to redirect to, or null
  */
 protected function getRedirectLocale()
 {
     // Redirection interfere with flushing, so don't redirect
     if (isset($_GET['flush'])) {
         return null;
     }
     // Don't redirect if the user has clicked a link on the locale menu
     if ($this->knownReferrer()) {
         return null;
     }
     // Redirect if this user has previously viewed a page in any locale
     if (Fluent::config()->remember_locale && ($locale = Fluent::get_persist_locale())) {
         return $locale;
     }
     // Detect locale from browser Accept-Language header
     if (Fluent::config()->detect_locale && ($locale = Fluent::detect_browser_locale())) {
         return $locale;
     }
 }
コード例 #2
0
function get_silverstripe_language()
{
    $locale = i18n::get_locale();
    if (class_exists('Fluent')) {
        $locale = Fluent::get_persist_locale();
    }
    $lang = i18n::get_lang_from_locale($locale);
    if ($lang == 'en') {
        return 'en_EN';
    }
    if ($lang == 'fr') {
        return 'fr_FR';
    }
    // Otherwise look in lang folder
    $ulocale = str_replace('-', '_', $locale);
    $lang_folder = dirname(__DIR__) . '/lang/';
    if (is_file($lang_folder . $lang . '.php')) {
        return $lang;
    }
    if (is_file($lang_folder . $ulocale . '.php')) {
        return $ulocale;
    }
    return 'en_EN';
}