Sunday, March 24, 2013

Localization in ASP.NET

Website Localization

Localization

 

http://msdn.microsoft.com/en-us/magazine/cc302030.aspx

http://msdn.microsoft.com/en-us/magazine/bb986108.aspx

Date.aspx

<%@ Page Language="C#" %>

<html>
  <body>
    <h1>
      <% Response.Write (DateTime.Now.ToShortDateString ()); %>
    </h1>
  </body>
</html>

 Global.asax

<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="System.Globalization" %>

<script language="C#" runat="server">
  void Application_BeginRequest (Object sender, EventArgs e)
  {
      try {
          if (Request.UserLanguages.Length > 0) {
              Thread.CurrentThread.CurrentCulture =
                  CultureInfo.CreateSpecificCulture
                  (Request.UserLanguages[0]);
          }
      }
      catch (ArgumentException) {
          // Do nothing if CreateSpecificCulture fails
      }
  }
</script>

 

Run the webform .       Now go to Tools | Internet Options | General and click on the Languages button to add "French (France) [fr]" to your language preferences and place it at the top of the list. Request Date.aspx again and the page will look quite different (see Figure 4). Include an Application_BeginRequest handler like the one in Figure 2 in every Web app you deploy and you'll gain a measure of culture awareness free of charge.

 

 

 

0 comments:

Post a Comment