Get language resource file based on user language : Request « I18N « ASP.NET Tutorial






<%@ Page Language="VB" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import namespace="System.Resources" %>
<%@ Import namespace="System.Threading" %>

<script runat="server">
   sub Page_Load(Sender as Object, e as EventArgs)
      dim objRM as ResourceManager

      dim strLanguage as string = Request.UserLanguages(0).ToString
      dim objCulture as new CultureInfo(strLanguage)
      Thread.CurrentThread.CurrentCulture = new CultureInfo(strLanguage)
      Thread.CurrentThread.CurrentUICulture = new CultureInfo(strLanguage)
      
      objRM = ResourceManager.CreateFileBasedResourceManager("data",Server.MapPath("."), Nothing)
      
      lblGreeting.Text = objRM.GetString("Greeting")
     
      objRM.ReleaseAllResources
   end sub   
</script>

<html><body>
   <b><asp:Label id="lblGreeting" runat="server"/></b> 
</body></html>


File: data.en-us.txt

Greeting=Welcome!

File: data.fr-fr.txt

Greeting=Bonjour!








22.5.Request
22.5.1.Request.UserLanguages
22.5.2.Get language resource file based on user language
22.5.3.Displaying a browser's language settings.