My site works this way:
- All content has autoroute for {culture/slug} URLs
- Users can select the site culture, so that everything is presented in the language they choose
I'm trying to achieve this functionality:
- User selects site in English.
- User goes to "site.com/es/content", which is a content in Spanish.
- The site has to automatically change the culture to Spanish and return the requested content.
What I think I need is to intercept the request, parse the URL and get the culture to see if it's the same as the current one.
I've tried getting it in the ItemsController in Orchard.Core.Contents using the IHttpContextAccessor but it doesn't have the raw Url.
I've also tried catching the request in Orchard.Autoroute and Orchard.Alias services but they are not the ones processing the request.
Any pointers would be appreciated.
There are some ways to do this.
Implement ICultureSelector
You can go wild in
GetCulture
, read headers, cookies, a query string or get some settings for the current user from DB. Whatever fits your need.Set the culture directly
Just change the current culture of
WorkContext
before returning your result and you're good to go.Fun fact: Changing the
WorkContext.Culture
in a controller will override everything you did in yourICultureSelector
implementation.