# Monday, May 11, 2009
Most application need some kind of localization, really. Today I will represent one simple possible solution for this in ASP.NET.

This localization is based on .NET resources (.resx). As name tells us resource is, well (re)source of something, typically strings. So as it looks like this resource file seems like perfect for our localization problem.

Resource file is XML base file type, it looks like this:


It also exist a resource editor, where you can easily edit resources:



Let's say our web application need localization support for two languages, English (default) and Slovene. First we create resource file for each supported language and for default one. So we create something like that:


Here we have a default support language (English) and other supported languages (for our case Slovene). You have to be careful with naming - naming convention is resource_name.[language code].resx.

And to the best part - code. All you have to is to set a CultureInfo to a current thread, and ASP.NET will automatically resolve a proper resource file. You can set in in your ASP.NET application file (Global.asax) like:
 System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cultureName);
Well, you a done, with localization of you application!

All is left is an actual use of it. Here you have one example:
 <asp:Literal runat="server" Text="<%$ Resources:Resource, strForm1Hello %>"/>
You can see I use build-in ASP.NET functionallity of resource reading instead of hard-coded string. Which is anyway good practice not to have it.


posted on Monday, May 11, 2009 7:59:23 AM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
Related posts:
Closing browser window from code
Validation service OnLine
EXECUTE permission denied
ASP.NET Response.Redirect("")
Comments are closed.