Hello everyone, how are you guy doing? hope all you guy doing great
.
Recently, I have been worked on an ASP.NET project that need to be able to switch languages from English to Khmer and from Khmer to English. After google for an hour i found the way to do this and this is call Localization in ASP.NET. So i decide to write this article to share what i have been done.
Localization in ASP.NET 4 is very easy because all of your language text are store in Resource file. You just open your resource file and input your language text, then write only one line of code to switch your language. To do so follow the below steps:
- Start your visual studio and create new ASP.NET web application.
- You can choose programming language you want VB.NET or C#.
- Visual studio will generate an ASP.NET web application like image below.
- switch to design time then drag and drop more Label and button to your default.aspx page.
- On tools menu, click Generate Local Resource.
- Back to your source code, you will notice that “meta:resourcekey” added to your label and button you just added above. Resource also created into your App_LocalResource folder.
- Now on your App_LocalResource folder, select Default.aspx.resx
- Copy and past new Resource file (Ctrl C, Ctrl V).
- Rename your new Resource file from “Copy of Default.aspx.resx” to “Default.aspx.km-KH.resx”.
- Remember that “km-KH” is a default culture string for Khmer Language.
- Open “Default.aspx.km-KH.resx”, you will see your your text and you can start translate it.
- So far so good, right? now your need to override the Culture to to switch language at runtime by add the following code.
- That’s it. Now you can run the application and your resource file will be apply on your page.
- The below image is my result of my project.
Next i will so you how to apply localization in WinForm application, so stay turn.
Happy programming…











