Accept-Langugage request header
j
Hi there. Do you know if Umbraco has a way to pass the request header accept-language with the culture given for the current page? I have a site that passes different culture from different web browsers (based on browser settings). I do not want this, I want it to come from Umbraco or my custom code.
s
I have no good answer at the moment but.. if I'm setting my browser to a specific culture, I really (REALLY) want websites to honor that. I am from Holland, but live in Denmark. However, in either case I've set my browser to English because I really don't want to read either Dutch or Danish. I get sad when people override my language preferences. 🥲
I think route hijacking might do the trick? https://docs.umbraco.com/umbraco-cms/reference/routing/custom-controllers you might be able to set headers.. or maybe this is too late in the pipeline in new dotnet .. then you'd probably need some kind of middleware instead.
j
The problem is that most users have no idea and we want to present the language that is set for the Umbraco page/site We have multiple sites with different languages in the same project so we have to set this somewhere. It is strange if you have a page with content in Swedish and dates come back formatted in english.
But maybe the custom controller may do the trick. I was hoping there was some easier config somewhere that I did not know about.
d
You might be able to do something with a localization provider perhaps? https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization/select-language-culture?view=aspnetcore-7.0 Not sure if it does anything, but worth a shot
j
Thanks. I was about to try to add culture / header in the startup conf but realized we don't know which site is visited by then. The solution above seems to require setting cookies in a controller action. Which means I have to override Umbracos controller. Seems like a lot of work for something that "feels quite basic". Anyway, I ended up setting request header in my API calls where I fetch data by javascript. It works for that. But the CookieBot text is still in the wrong language since it is based on the current page headers. But I leave that for now. Maybe someone from Umbraco reads this and get inspired to add request header from the current site culture, at least Content-Language if they don't want to override the browser / user setting with Accept-Language 😄 😉
2 Views