Their are 3 Methods for developing multi-language websites:
1. Replication 2. Generalized approach 3. Using Concept of Localization and Globalization
Replization: This is basic approach used in static websites. In this approach you need to
create replica of each web page in different languages. Suppose you have 100 web pages in
your web site and you want to provide same content in 3 languages then you have to create
300 pages for it.
This is totally incorrect approach.
Generalized approach: This approach is supported in ASP.NET version 1.1, 2.0, 3.5 and
4.0. Means this approach is supported by all version of ASP.NET.
Localization and Globalization: This approach was introduced in ASP.NET version 3.5 and
4.0
Both of these approaches has their on advantages. Buth their is no disadvantage.
Now starting with Generalized approach:
First you need to have language name and their code: Language Code -------------------------------------------------------- English en-us French fr-be German de-at
To get more language code: Select Internet option in internet explorer > Select Languages Step 1: Create new website. Add Three text file and name them: a. abc.en-us.txt b. abc.fr-be.txt c. abc.de-at.txt
In this naming convention. abc: Base name en : Culture code us : Region Code txt: File Extension Step 2: Specify key and their value in these files: a. abc.en-us.txt a=This is Techsapphire b=English b. abc.fr-be.txt a=c'est www.techsapphire.in b=French c. abc.de-at.txt a=Dies ist www.techsapphire.in b=German
Step 3: Convert these files into resource files (File with extension *.resources). a. Open Visual Studio Command prompt. b. Move to web directory using command prompt. c. Use "resgen" utility to convert these files to resouces. Example: >resgen abc.en-us.txt >resgen abc.fr-be.txt >resgen abc.de-at.txt These command will create 3 files: a. abc.en-us.resources b. abc.fr-be.resources c. abc.de-at.resources
Step 4: Add Global Application Class to you web project: Global.asax
Add name space to this file: <%@ Import Namespace="System.Globalization" %> <%@ Import Namespace="System.Resources" %> <%@ Import Namespace="System.Threading" %>
using System.Globalization; using System.Resources; using System.Threading; public partial class _Default : System.Web.UI.Page { ResourceManager rm; protected void Page_Load(object sender, EventArgs e) { rm = (ResourceManager)(Application["aa"]); if (!IsPostBack) { lb1.Text = rm.GetString("a").ToString(); lb2.Text = rm.GetString("b").ToString(); } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { setlang(DropDownList1.SelectedValue); } private void setlang(string d) { Thread.CurrentThread.CurrentUICulture = new CultureInfo(d); lb1.Text = rm.GetString("a").ToString(); lb2.Text = rm.GetString("b").ToString(); } }
Step 5: Test your website by changing your browser language. (Note: In browser the language specified at top of the list is default language.)
Concept of Localization and Globalization: In this localized resources are page specific and global resources are project specific.
In this approach you don't need to create txt files and then converting them to resource
file. You could directly create resouce file. You could also specify key attributes.
Step 1: Crete New Website. Add New ASP.NET Folder: a. App_LocalResources b. App_GlobalResources
Step 2: Add 3 Resource file to App_LocalResources (As local resources are page specific
so base name here would be page base name): a. Default.aspx.resx > This one will also be used as default resource file b. Default.aspx.fr-be.resx c. Default.aspx.de-at.resx
Add Key and their properties in resource file: Default.aspx.resx
String Value Comment -------------------------------------------------- ab.text This is English ab.tooltip This is English other Other English
Default.aspx.fr-be.resx
String Value Comment -------------------------------------------------- ab.text This is French ab.tooltip This is French other Other French
Default.aspx.de-at.resx
String Value Comment -------------------------------------------------- ab.text This is German ab.tooltip This is German other Other German
Add Resource file with any name to App_GlobalResources Anyname.resx
String Value Comment -------------------------------------------------- Glob Other Global
Step 3: Add Default.aspx (Note: Add Culture="Auto" Uiculture="Auto" to File declaration. As Specified in