Globalization implementation in Asp.net

Susanthampy
Posted by in ASP.NET category on for Beginner level | Points: 250 | Views : 28486 red flag
Rating: 4.63 out of 5  
 24 vote(s)

Globalization is the process of developing an application that funcations for multiple cultures. A web form page have 2 culture values Culture and UICulture. Culture is user for culture dependent functions like date, currency etc. So it is mainly used for date formatting, number formatting etc. UICulture is used to identify which language the resource should load.

Globalization

Globalization is the process of developing an application that functions for multiple cultures.

In web.config file,
<globalization fileEncoding="utf-8" 
requestEncoding="utf-8" 
responseEncoding="utf-8" 
culture="en-US" 
uiCulture="fr-FR"/>
In Code Behind page,

Add 2 namespaces,
1.System.Treading and
2.System.Globalization.

Then Add the below code,
First select the culture value and store that value in a string named strCulture,
CultureInfo objCI = new CultureInfo(strCulture);
Thread.CurrentThread.CurrentCulture = objCI;
Thread.CurrentThread.CurrentUICulture = objCI;
In Code Inline page,
<%@ Page UICulture="fr" Culture="en-US" ....%>
Asp.net wont automatically translate the contents in one language to another language by using culture. So we should create a resource file and add all the strings into the resource file as key, value pairs, we need to display in our application. Also we need to translate the string into different languages.

Resource Files

Resource files are the files with resx extension. Resource file storing strings in a key, value pair manner like hashtable. For each language we need to use in our application have different resource files we are using. In each resource file the key name is same but the value is changing. We are using one common resource file, in the common file usually we are storing English language.

Steps to create resource file,

1.In Solution Explorer right click on Project---->Add--->Add ASP.NET Folder--->App_GlobalResources.
One folder will appear on our solution explorer named App_GlobalResources.

1



















2. Right click on App_GlobalResources folder--->Add--->New Item--->Resource File.
Name the file as My_Resources.fr-FR.resx for French, My_Resources.en_US for English etc.

Example for Resource file,

2
























Code for accessing resource file values 


Code Behind    
string strCulture = ddlLanguage.SelectedValue.ToString();
Session["SelectCulture"] = strCulture;
CultureInfo objCI = new CultureInfo(strCulture);
Thread.CurrentThread.CurrentCulture = objCI;
Thread.CurrentThread.CurrentUICulture = objCI;
lblHeading.Text = Resources.My_Resource.DatabaseAdministration;
lblIntro.Text = Resources.My_Resource.Introduction;
lblHead.Text = Resources.My_Resource.PlsLogin;

Conclusion

This will output content based on the language selected. Globalization is useful for multiple language presentation in web sites

Reference

http://www.codeproject.com/KB/locale/GlobalizationSample.aspx

Page copy protected against web site content infringement by Copyscape

About the Author

Susanthampy
Full Name: Susan Thampy
Member Level: Bronze
Member Status: Member,MVP
Member Since: 4/25/2011 3:55:56 AM
Country: India
Regards, Susan
http://www.dotnetfunda.com
I am completed my graduation in BSc Computer Science from MG University on 2010 . Currently I am working as a software Engineer in ASSYST International, Cochin, Kerala.

Login to vote for this post.

Comments or Responses

Posted by: Ravi_pinnoju on: 4/27/2011 | Points: 25
It is good.
Posted by: Susanthampy on: 4/27/2011 | Points: 25
thank u Ravi_pinnoju
Posted by: Rijeshkn on: 5/24/2011 | Points: 25
nice dear...thanks....
Posted by: Jayeshl on: 6/17/2011 | Points: 25
thanks friend to write this ..


from
Jayesh L
http://www.sqlassistant.blogspot.com
Posted by: Susanthampy on: 6/22/2011 | Points: 25
Welcome Jayesh
Posted by: Susanthampy on: 6/22/2011 | Points: 25
Thank u Rijesh
Posted by: Lakn2 on: 6/30/2011 | Points: 25
good one
Posted by: Sheebaas on: 8/19/2011 | Points: 25
Nice job

Login to post response

Comment using Facebook(Author doesn't get notification)