Howto detect browser languagehttp://forums.asp.net/t/1052219.aspx/1?Howto+detect+browser+languageSun, 10 Dec 2006 00:48:34 -050010522191489259http://forums.asp.net/p/1052219/1489259.aspx/1?Howto+detect+browser+languageHowto detect browser language <p>Hi,&nbsp;</p> <p>How can I detect the language of the browser, i want to select the language for the browser.</p> <p><br> &nbsp;</p> 2006-12-07T07:02:36-05:001489388http://forums.asp.net/p/1052219/1489388.aspx/1?Re+Howto+detect+browser+languageRe: Howto detect browser language <p class="MsoNormal" style="margin:0cm 0.5pt 0pt"><span style="font-size:14pt; color:#000066; font-family:'Courier New'">HttpBrowserCapabilities bc = Request.Browser;</span></p> <p class="MsoNormal" style="margin:0cm 0.5pt 0pt"><span style="font-size:14pt; color:#000066; font-family:'Courier New'">Response.Write(&quot;Supports VB Script = &quot; &#43; bc.VBScript &#43; &quot;&lt;br&gt;&quot;);</span></p> <p class="MsoNormal" style="margin:0cm 0.5pt 0pt"><span style="font-size:14pt; color:#000066; font-family:'Courier New'">Response.Write(&quot;Supports JavaScript = &quot; &#43; bc.JavaScript &#43; &quot;&lt;br&gt;&quot;);</span></p> <p class="MsoNormal" style="margin:0cm 0.5pt 0pt"><span style="font-size:14pt; color:#000066; font-family:'Courier New'">Response.Write(&quot;Supports Java Applets = &quot; &#43; bc.JavaApplets &#43; &quot;&lt;br&gt;&quot;);</span></p> <span style="font-size:14pt; color:#000066; font-family:'Courier New'">Response.Write(&quot;Supports ActiveX Controls = &quot; &#43; bc.ActiveXControls &#43; &quot;&lt;br&gt;&quot;);</span> 2006-12-07T09:56:51-05:001489396http://forums.asp.net/p/1052219/1489396.aspx/1?Re+Howto+detect+browser+languageRe: Howto detect browser language <p>You could look at using the System.Globalization and CultureInfo, there is a write up here and some example code<br> </p> <p>http://quickstarts.asp.net/QuickStartv20/aspnet/doc/localization/culture.aspx#autoculture</p> <p>&nbsp;Hope it helps<br> &nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> 2006-12-07T10:03:33-05:001489409http://forums.asp.net/p/1052219/1489409.aspx/1?Re+Howto+detect+browser+languageRe: Howto detect browser language <p>Hi,</p> <p>ASP.NET 2.0 Support <strong>Auto Detection of Browser Language - </strong>you can&nbsp;determine the language of the requesting browser from user's culture.</p> <p><a href="http://quickstarts.asp.net/QuickStartv20/aspnet/doc/localization/default.aspx">http://quickstarts.asp.net/QuickStartv20/aspnet/doc/localization/default.aspx</a></p> <p><a href="http://samples.gotdotnet.com/quickstart/aspplus/doc/localizingapps.aspx">http://samples.gotdotnet.com/quickstart/aspplus/doc/localizingapps.aspx</a></p> <p>&nbsp;</p> 2006-12-07T10:24:02-05:001492029http://forums.asp.net/p/1052219/1492029.aspx/1?Re+Howto+detect+browser+languageRe: Howto detect browser language <p>&nbsp;</p> <p>ASP.NET 2.0 has a couple of facilities to auto-detect locales and switch the thread's locale to the browser locale. Look for the &lt;globalization&gt; section in web.config (which is global obviously) or the Culture and UICulture attributes on the @Page directive.</p> <p>You can also do this manually in your code by looking at Browser.UserLanguages which returns all the user's browser languages that are configured in her browser. Here's a routine I use in my most of applications to switch the culture and UICulture:</p> <pre class="prettyprint">/// &lt;summary&gt; /// Sets a user's Locale based on the browser's Locale setting. If no setting /// is provided the default Locale is used. /// &lt;/summary&gt; public static void SetUserLocale(string CurrencySymbol, bool SetUiCulture) { HttpRequest Request = HttpContext.Current.Request; if (Request.UserLanguages == null) return; string Lang = Request.UserLanguages[0]; if (Lang != null) { // *** Problems with Turkish Locale and upper/lower case // *** DataRow/DataTable indexes if (Lang.StartsWith(&quot;tr&quot;)) return; if (Lang.Length &lt; 3) Lang = Lang &#43; &quot;-&quot; &#43; Lang.ToUpper(); try { System.Globalization.CultureInfo Culture = new System.Globalization.CultureInfo(Lang); if (CurrencySymbol != null &amp;&amp; CurrencySymbol != &quot;&quot;) Culture.NumberFormat.CurrencySymbol = CurrencySymbol; System.Threading.Thread.CurrentThread.CurrentCulture = Culture; if (SetUiCulture) System.Threading.Thread.CurrentThread.CurrentUICulture = Culture; } catch { ;} } }</pre> <p>I prefer doing this manually rather than letting ASP.NET's Auto features do this because typically you'll need to configure additional local settings like the currency symbol explicitly. If you do you need to create a new culture info anyway and so this is a more consistent way to do it... You should call this soemwhere early in the ASP.NET lifecycle like Application_BeginRequest...</p> <p>Hope this helps,</p> <p>&#43;&#43;&#43; Rick ---</p> <p>&nbsp;</p> 2006-12-10T00:48:34-05:00