Saturday, July 11, 2009

Localizing ASP.NET pages using resources

Localizing ASP.NET pages using resource files is an easy thing to do. It requires just a few steps to get everything up and running but all of those steps have to be completed because otherwise it will not work.

  • Set the UICulture and Culture attributes on a page to "Auto"
  • Create an ASP.NET folder named App_LocalResources
  • In App_LocalResources create a resource file using the following pattern:
page.ext.lang-variant.resx

for example:

Default.aspx, en-us -> Default.aspx.en-us.resx
Default.aspx, pl -> Default.aspx.pl.resx

  • On the element that needs localization set the attribute meta:resourcekey to something meaningful, for example:

<asp:Label ID="LblText" Text="Hello, world!" runat="server" />

becomes

<asp:Label ID="LblText" Text="Hello, world!" meta:resourcekey="LblText" runat="server" />

  • Add resource key for the property to modify using the following pattern:

resourcekey.property

for example:

LblText.Text

  • DO NOT FORGET TO REBUILD AND RE-RUN THE APPLICATION!


Here's a complete and working solution for you to play around

ASP.NET-Localization.zip

Have fun!

No comments: