November Happy Hour will be moved to Thursday December 5th.

Routing: How to use own language priority logic?

Vote:
 

As for the routing, is there any way to have a full control over the priority of languages?

I need to have a custom priority list that is based on route segments, browser language and site default language, but it's different than ContentLanguageImplementation.LanguagePreferenceList.

Maybe there's a way to override the LanguagePreferenceList and use it for the app logic, but the question is - how can this be achieved?

#297318
Edited, Feb 27, 2023 12:23
Eric Herlitz - Feb 27, 2023 18:26
Using MVC, Content delivery or how do you build you site?
Dariusz Woźniak - Feb 27, 2023 19:18
@Eric: Both MVC and Content Delivery API.
Vote:
 

This area is very complex. IMO, there are too many abstractions for culture handling and too many options to solve this in a good way. Also, the fact that many potential entry points has been made internal does not make it easier. Your solution might become something very different from mine.

In the end I only used a custom IResourceFilter and placed it before the existing CurrentCultureFilter. So, this only applies for the MVC pipeline - not the entire middlewares pipeline. This only works if RequestLocalizationMiddleware is NOT used.

If you create your own IResourceFilter, you can apply your own logic and figure out what culture to use for the request. First set content language via IUpdateCurrentLanguage, then set culture and UI culture via ICurrentCultureContext. ICurrentCultureContext will subsequently be used in EPiServer.Globalization.Internal.CurrentCultureFilter, and given that you have provided cultures - these cultures will be set on Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture - which is what you want.

Given that all your requests pass through the MVC pipeline, this should hopefully give you full control over content language and system language, which should be enough.

#297346
Feb 27, 2023 20:03
Vote:
 

Thank you Andreas J for the information.

Actually I was not doing with URL customization, but to add additional note - while I was investigating the topic - I've found that IContentUrlGeneratorEvents and IContentUrlResolverEvents might help to solve the problem.

#297909
Mar 08, 2023 11:56
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.