public static function domain_for_locale($locale) { foreach (self::domains() as $domain => $config) { if (!empty($config['locales']) && in_array($locale, $config['locales'])) { return $domain; } } }
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); }