Fluent::locales PHP Method

locales() public static method

Retrieves the list of locales
public static locales ( mixed $domain = null ) : array
$domain mixed Domain to determine the locales for. If null, the global list be returned. If true, then the current domain will be used.
return array List of locales
    public static function locales($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['locales'])) {
                return $info['locales'];
            }
        }
        // Check for configured locales
        if ($locales = self::config()->locales) {
            return $locales;
        }
        // If no locales are configured, then fallback to the global default locale
        // This should ensure the site is at least usable if a dev/build is performed prior to
        // configuration of `Fluent.locales`
        return array(self::default_locale());
    }

Usage Example

コード例 #1
0
 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::locales