I see that there are similar questions to this one but I haven't found an answer to my question there and therefore, I decided to ask a question to my own.
The situation: I want to get the user's browser language so that I can set his session culture key or store the localization in the database if the user has an account in order to show this user my website on his language until he changes his lang preference manually.
My issue is: Everything seems to work pretty fine in theory but...
These are my browser language preferences I know that they are set on particular order
That order is sent to the server exactly as it is no matter that my browser display language is set to Bulgarian my preference still remain en-US
This is a sample code snippet to show what my dev tools console says about my browser display language
And in my code I cannot know what is the browser language I can only get the preferred language to the user then I get the Languages[0]
Is there a way to get this display language. I cannot use JS to send it because I have a problem that my first request is always displaying the page in English than when the session is set it displays it localized. Probably there is a workaround to check and set a particular header from JS but I am thinking of a more gallant way to do it only with C#.
I am not sure it is the proper way. I have overridden on OnActionExecuting in my BaseController and I am setting the current thread's localizations based on the user's locale and he may change by drop down his preferred language also that overrides and reset the session language key. I know also that there is an auto locale option but I am not sure if it is good enough and also I don't know how it works and how can a user simply change his language while the auto globalization is turned on.
For now, I just want to get the proper browser display's language and I need some help from someone that has dealt with localizations.
you can use CultureHelper :
then in your view use :