/** * We need to disable Translatable before retreiving the DataObjects or * Pages for the sitemap, because otherwise only pages in the default * language are found. * * Next we need to add the alternatives for each Translatable Object * included in the sitemap: basically these are the Translations plus * the current object itself * * @return Array */ public function sitemap() { Translatable::disable_locale_filter(); $sitemap = parent::sitemap(); Translatable::enable_locale_filter(); $updatedItems = new ArrayList(); foreach ($sitemap as $items) { foreach ($items as $item) { if ($item->hasExtension('Translatable')) { $translations = $item->getTranslations(); if ($translations) { $alternatives = new ArrayList(); foreach ($translations as $translation) { $translation->GoogleLocale = $this->getGoogleLocale($translation->Locale); $alternatives->push($translation); } $item->GoogleLocale = $this->getGoogleLocale($item->Locale); $alternatives->push($item); $item->Alternatives = $alternatives; } $updatedItems->push($item); } } } if (!empty($updatedItems)) { return array('Items' => $updatedItems); } else { return $sitemap; } }
/** * Specific controller action for displaying a particular list of links * for a class * * @return mixed */ public function sitemap() { if ($this->request->param('ID') == 'SiteTree') { //Disable the locale filter Translatable::disable_locale_filter(); $items = parent::sitemap(); //Re-enable the locale filter Translatable::enable_locale_filter(); return $items; } else { return parent::sitemap(); } }
<?php SiteTree::add_extension("LocaleDomainSiteTreeExtension"); if (class_exists("GoogleSitemapController")) { GoogleSitemapController::add_extension("LocaleDomainsGoogleSitemapControllerExtension"); }
public function init() { parent::init(); // Reset any session locale to use the default locale as the standard 'base' locale Fluent::set_persist_locale(Fluent::default_locale(true)); }