diff --git a/core/model/Translatable.php b/core/model/Translatable.php index 1e570c32b..ee875ebec 100755 --- a/core/model/Translatable.php +++ b/core/model/Translatable.php @@ -634,6 +634,10 @@ class Translatable extends DataObjectDecorator { * nested pages accessible in a translated CMS page tree. * It would be more userfriendly to grey out untranslated pages, * but this involves complicated special cases in AllChildrenIncludingDeleted(). + * + * {@link SiteTree->onBeforeWrite()} will ensure that each translation will get + * a unique URL across languages, by means of {@link SiteTree::get_by_url()} + * and {@link Translatable->alternateGetByURL()}. */ function onBeforeWrite() { // If language is not set explicitly, set it to current_locale. @@ -661,18 +665,6 @@ class Translatable extends DataObjectDecorator { } } - // Specific logic for SiteTree subclasses. - // Append language to URLSegment to disambiguate URLs, meaning "myfrenchpage" - // will save as "myfrenchpage-fr" (only if we're not in the "default language"). - // Its bad SEO to have multiple resources with different content (=language) under the same URL. - if($this->owner->hasField('URLSegment')) { - if(!$this->owner->ID && $this->owner->Locale != Translatable::default_locale()) { - $SQL_URLSegment = Convert::raw2sql($this->owner->URLSegment); - $existingOriginalPage = Translatable::get_one_by_lang('SiteTree', Translatable::default_locale(), "\"URLSegment\" = '{$SQL_URLSegment}'"); - if($existingOriginalPage) $this->owner->URLSegment .= "-{$this->owner->Locale}"; - } - } - // Has to be limited to the default locale, the assumption is that the "page type" // dropdown is readonly on all translations. if($this->owner->ID && $this->owner->Locale == Translatable::default_locale()) { diff --git a/tests/model/TranslatableTest.php b/tests/model/TranslatableTest.php index dd502913b..8f29c268d 100644 --- a/tests/model/TranslatableTest.php +++ b/tests/model/TranslatableTest.php @@ -174,12 +174,13 @@ class TranslatableTest extends FunctionalTest { ); } - function testTranslationCanHaveSameURLSegment() { + function testTranslationCantHaveSameURLSegmentAcrossLanguages() { $origPage = $this->objFromFixture('Page', 'testpage_en'); $translatedPage = $origPage->createTranslation('de_DE'); $translatedPage->URLSegment = 'testpage'; - - $this->assertEquals($origPage->URLSegment, $translatedPage->URLSegment); + $translatedPage->write(); + + $this->assertNotEquals($origPage->URLSegment, $translatedPage->URLSegment); } function testUpdateCMSFieldsOnSiteTree() {