Home
About Me
Photos
Videos
Blog
Links
How To
Contact Me
English
Magyar
ASP.NET - Simple Globalization / Localization
12/12/2009
Why?
Localization is a means of adapting something (In this case a website) in to a different language and to apply regional changes.
Microsoft often refers to Localization as Globalization which can confuse as Globalisation is an economic term and be easily misinterpreted. That said I have used the word Globalization in this article as well as Localization as I am writing this using a Microsoft product.
The main reason for you to localize your site is so that it can be presented in another language. This is very simple to do in theory but very difficult to manage and maintain if you have content added frequently or your site contains technical or language specific content (e.g. Jokes or slang).
On this very site I am using Localization to display the site content in Hungarian if either the Browser Default Language is hu-HU or if “Magyar” is selected from the dropdown at the top right of the page.
In this “How To” I will be focusing on the Simplest form of Localization which is to set based on Browser Language.
Alternatives
I cannot honestly think of an alternative to Localization other than not doing it!!
I guess the “alternative to Localization” should be “Methods to implement Localization”, In which case 3 Spring to mind (Resource Files, Database, Redirect).
How To
Open Visual Studio Web Developer Express.
Select 'Web Site' Create Option in the "Recent Projects" area
A pop up will appear asking you which Project template you wish to load.
Select "ASP.NET Web Site" and Click "OK"
The Template will load and you will see the files "Default.aspx" and "web.config".
Right Click on the Project Name (Actually shows file location) and select "App_GlobalResources" from the "Add AS.NET Folder" menu.
The "App_GlobalResources" Folder will be created at the root of your Web Site. Right Click on it and select "Add New Item"
A pop up will appear and you should select "Resource File" and for the purposes of this tutorial call the file "Language.resx". Click "Add"
The new resource file will be loaded in to the main view.
Type "HelloWorld" in to the Name Column and "Hello World" in the value Column
Create a new resource file follwing the steps above but name it "Language.fr.resx". It will appear in the App_GlobalResources" folder.
The new resource file (Language.fr.resx) will be loaded in to the main view.
Type "HelloWorld" in to the Name Column and "Bonjour tout le monde" in the value Column
Save and close the resource files in the main view and open the "Default.aspx" page if it is not already open.
Type the following in to the page declaration at the top
Culture="auto" UICulture="auto"
Add the Following immediately after the <div> tag and imeediately before the </div> tag.
<asp:Label ID="Label1" runat="server" Text="<%$ Resources:Language, HelloWorld %>"><asp:Label>
Save the Page
Press F5 to Debug and a window will pop up asking you if you wish to "Modify the Web.config file to enable debugging." Just press the OK Button.
The Web Site will now load in your default Browser (Firefox in my case) and you should see the text "Hello World".
So far so good.
Change the default language of your browser and refresh the page you should now see "Bonjour tout le mode".
Summary
This is about as easy as it gets. You can implement Localization in lots of different ways and in lots of different formats but the above is what I personally find easiest.
Further Information
Wiki - Internationalization and localization
ASP.NET Globalization and Localization
Terms of Usage/Privacy Policy
© 2010 Mike Spraggett