Browser language detection

In XbyK is detecting the user's language "standard" .NET functionality we implement now or some other Kentico middleware that XbyK has?  Not finding much documentation on it in XbyK, just KX13 and earlier.  The "Ask AI" feature in the Kentico docs says this:

For automatic language detection, you would typically need to:

  • Detect the user's preferred language (e.g., from the browser'sAccept-Languageheader).
  • Redirect the user to the appropriate language version of your site based on that preference.
  • Ensure your URL routing supports language codes (e.g.,/en/,/es/).


While this logic isn't provided out-of-the-box, you can implement it in your site's startup or middleware logic.


Any direction would be great because what we did in KX13 doesn't seem to be working with XbyK when I expect it should.


Environment

  • Xperience by Kentico version: [31.7.1]

  • .NET version: [10]

  • Execution environment: [SaaS]

Tags:
Localization SaaS v31.7.0

Answers

Using the browser's Accept-Language header is a very good way to do it, but we normally let the language be determined by the URL using XbyK's IPreferredLanguageRetriever. This prevents a redirect from happening when a user may have specifically navigated to language URL that is different than their default.

You can also use .NET's request localizaiton middleware, which uses Accept-Language under the hood if a cookie or query string doesn't override it. This will automatically set CultureInfo.CurrentCulture.
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization/select-language-culture

Thanks Mike.

The client is hoping for something that auto detects the language upon first request. For instance if the user is in France and has French as their browsers default language that is what would be served up. We have the default as you mentioned using the IPreferredLanguageRetriever just not sure how to enhance it more.

To response this discussion, you have to login first.