Internationalization
The toolbox package includes some helpers for locale dependent url generations.
Locale dependent url generation
Consider a customer page that has two different pages; one in Norwegian and English. Both english and norwegian has a News section that shows different news.
Domain | Route | Name |
---|---|---|
test.no |
|
|
test.co.uk |
|
|
Given a similar url structure, the LocaleDependentUrlGenerator
will allow you to write
regardless of which site you are on, but will navigate to /news
when on test.co.uk
and /nyheter
when on test.no
.
Usage
The middleware does require some setup in order for it to work just like the laravel one. You can adjust your RouteServiceProvider or use the LocaleDependentUrlGenerator trait that configures it, and then running registerLocaleDependentUrlGenerator()
function.
Setting locale in edit and preview mode
Since we don't really have control over the edit and preview mode endpoint and the endpoint will be to the same domain, regardless of what domain the viewed should have, most common domain/locale resolvers we use might not work for edit/preview mode.
In order to get around this issue, extending __current_page__
in the service provider can give you a simple way of adjusting the locale by using it as some sort of middleware system.
While probably not a very clean solution, it does allow us to ensure we also set the locale when we're fetching the page.