Hey guys, I am trying to make SilverStripe allow the same URLSegment across different locales. This works because I am using the language in the URL in the format domain.com/eng/contact/ and domain.com/fra/contact/.
I figured out that the "problem" is in SiteTree's onBeforeWrite() or more precisely validURLSegment(). What I did was to add the locale to the existingPage query. The final method looks like this: http://www.sspaste.com/paste/show/4ee9ea6f46b04 (lines 23-26 + line 31).
This alone didn't work and I found out that I also have to modify Translatable's augmentValidURLSegment() which now looks like this: http://www.sspaste.com/paste/show/4ee9eb02a6afe (lines 17-20 + line 24 the same way as validURLSegment()).
With these two changes, having same URLs across locales appeared to work, but it doesn't fully. In some cases, SilverStripe renames the page to contact-2 when publishing, but ONLY in the SiteTree_Live table and NOT in the SiteTree table. Also, calling domain.com/fra/contact works as expected so you don't have to call domain.com/fra/contact-2.
Another problem resulting from this is that SilverStripe messes up something when it comes to checking whether a page was published or not. Example:
- 1. Set default locale to en_GB and build default DB
- 2. Create page in en_GB and publish
- 3. Create translation of page in de_DE and publish
- 4. Switch back to en_GB and publish the page again
- 5. Switch to de_DE --> the page appears as not published
The most weird thing is that if I simply uncomment the loop responsible for generating unique URLSegments in onBeforeWrite() so that validURLSegment() and augmentValidURLSegment() are not being called, the problem above cannot be reproduced, but as far as I understand those functions, they only return true or false if a page with that name already exists, so they're not responsible for generating new names themselves.
What am I doing wrong?