View more context



it'll have loaded that fluentstate somehow, I'd recommend checking out how that object gets created and passed around (starts in the middleware IIRC)


Mmmm, I was hoping to find something like getLocaleURLPrefix() similar to getAction() that'd return the locale portion from the current url else null or false if it doesn't exist. It looks like routing rules are generated and inserted for each locale. There's multiple ways to get the current locale, whether it's set in the url or not, but it seems to reliably retrieve the locale prefix from a url doesn't exist as an existing method on any class which I've seen.

Show 1 attachment(s)

Multi-language translate module for Silverstripe, without having to manage separate site trees. - tractorcow-farm/silverstripe-fluent

Hide attachment content

I've created this small method to detect whether a locale prefix exists in the url, then to redirect if it doesn't exist, but a default locale does exist.

Interestingly, $this->getRequest()->getURL() may not contain the locale prefix, but $this->Link() most often does contain the appropriate locale prefix which I'm assuming gets generated after routing rules are processed. Quite handy.


@taoceanz you're right there's no one place you can get that prefix; However you can copy the code from FluentSiteTreeExtension::updateRelativeLink() to get that


Logic like disable_default_prefix is important for calculating the prefix 😉


Is there a way to force the default locale? On our site, en_US is default, but in a new browser it consistently loads in Chinese.


Will detect_locale interfere with the routing and locale detection by setting a higher precedence on the detected locale over the "default" locale?