Fluent::default_locale PHP Method

default_locale() public static method

Retrieves the default locale
public static default_locale ( mixed $domain = null ) : string
$domain mixed Domain to determine the default locale for. If null, the global default will be returned. If true, then the current domain will be used.
return string
    public static function default_locale($domain = null)
    {
        if ($domain === true) {
            $domain = strtolower($_SERVER['HTTP_HOST']);
        }
        // Check for a domain specific default locale
        if ($domain && ($domains = self::domains()) && !empty($domains[$domain])) {
            $info = $domains[$domain];
            if (!empty($info['default_locale'])) {
                return $info['default_locale'];
            }
            // With no explicitly set default_locale use the first locale assigned
            if (!empty($info['locales'])) {
                return reset($info['locales']);
            }
        }
        return self::config()->default_locale;
    }

Usage Example

 public function updateRelativeLink(&$base, &$action)
 {
     // Don't inject locale to subpages
     if ($this->owner->ParentID && SiteTree::config()->nested_urls) {
         return;
     }
     // For blank/temp pages such as Security controller fallback to querystring
     $locale = Fluent::current_locale();
     if (!$this->owner->exists()) {
         $base = Controller::join_links($base, '?' . Fluent::config()->query_param . '=' . urlencode($locale));
         return;
     }
     // Check if this locale is the default for its own domain
     $domain = Fluent::domain_for_locale($locale);
     if ($locale === Fluent::default_locale($domain)) {
         // For home page in the default locale, do not alter home url
         if ($base === null) {
             return;
         }
         // For all pages on a domain where there is only a single locale,
         // then the domain itself is sufficient to distinguish that domain
         // See https://github.com/tractorcow/silverstripe-fluent/issues/75
         $domainLocales = Fluent::locales($domain);
         if (count($domainLocales) === 1) {
             return;
         }
     }
     // Simply join locale root with base relative URL
     $localeURL = Fluent::alias($locale);
     $base = Controller::join_links($localeURL, $base);
 }
All Usage Examples Of Fluent::default_locale