Google Search: C#, Finding the Locale

I have had a search against my site for finding the User Locale in C#.There are a couple of ways that this can be done. If you are using ASP.Net you can look at the Request.UserLanguages string array to see what preferences they have set up. The first locale in the array should be the locale that they normally work. Obviously this is browser dependent and user configuration dependent.Using this information you could then set the threads culture (so that all comparisons etc are performed with the correct culture awareness) using the following piece of code:Thread.


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan

<p>I have had a search against my site for finding the User Locale in C#.<p />There are a couple of ways that this can be done. If you are using ASP.Net you can look at the Request.UserLanguages string array to see what preferences they have set up. The first locale in the array should be the locale that they normally work. Obviously this is browser dependent and user configuration dependent.<p />Using this information you could then set the threads culture (so that all comparisons etc are performed with the correct culture awareness) using the following piece of code:<p />Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);<p />If it is a Winform or Service you could get the Current Culture just by inspecting the either:Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;orThread.CurrentThread.CurrentCulture.ThreeLetterISOLanguageName;orThread.CurrentThread.CurrentCulture.ThreeLetterWindowsLanguageNameorThread.CurrentThread.CurrentCulture.EnglishName;orThread.CurrentThread.CurrentCulture.DisplayName;<p /></p>


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan


Print Share Comment Cite Upload Translate Updates
APA

Paul Kinlan | Sciencx (2006-03-08T00:00:00+00:00) Google Search: C#, Finding the Locale. Retrieved from https://www.scien.cx/2006/03/08/google-search-c-finding-the-locale/

MLA
" » Google Search: C#, Finding the Locale." Paul Kinlan | Sciencx - Wednesday March 8, 2006, https://www.scien.cx/2006/03/08/google-search-c-finding-the-locale/
HARVARD
Paul Kinlan | Sciencx Wednesday March 8, 2006 » Google Search: C#, Finding the Locale., viewed ,<https://www.scien.cx/2006/03/08/google-search-c-finding-the-locale/>
VANCOUVER
Paul Kinlan | Sciencx - » Google Search: C#, Finding the Locale. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2006/03/08/google-search-c-finding-the-locale/
CHICAGO
" » Google Search: C#, Finding the Locale." Paul Kinlan | Sciencx - Accessed . https://www.scien.cx/2006/03/08/google-search-c-finding-the-locale/
IEEE
" » Google Search: C#, Finding the Locale." Paul Kinlan | Sciencx [Online]. Available: https://www.scien.cx/2006/03/08/google-search-c-finding-the-locale/. [Accessed: ]
rf:citation
» Google Search: C#, Finding the Locale | Paul Kinlan | Sciencx | https://www.scien.cx/2006/03/08/google-search-c-finding-the-locale/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.