Share
More
Next Blog
Create Blog
Sign In
D Murli
Tuesday, October 30, 2012
B l o gA r c h i v e
2014 (2) 2013 (27) 2012 (56) December (2) November (3) October (8) Create Resource/Multilingua l Files on your page. Creating multilingual website (English / Hindi / P... MVC 3 with Razor client-side validation MVC Interview Questions JQuery getJSON call to MVC Controller Call PageMethod From JavaScript in ASP.NET Ajax How is ASP.NET MVC different from ASP.NET WebForms... Anonymous Methods September (4) August (2) July (9) June (22) February (5) January (1) 2011 (34) 2010 (67) 2009 (14)
W h a ti st h el o g i cb e h i n dt h i s?
There are two ways to convert content written in one language into another. Translation and Transliteration. During translation we keep the meaning of the sentence intact. We convert a sentence in some other language which has the same meaning in that language. For example if i translate I need to drink water in some other language, then i would speak this sentence in that language by keeping the meaning intact. Transliteration is the practice of converting a text from one writing system into another in a systematic way. For example when you write a message in your local language by using English, you are doing transliteration. When we change the language of the asp.net website from one language to another, we are neither doing translation nor doing transliteration ! We are simple reading content from different files and just displaying what ever is written in those files. The website or the browser has no information as to which language is being displayed. The asp.net website just reads the content from the file and displays it. Its your responsibility to write content in different languages and keep them in proper files. If you make a mistake in writing or arranging the content, the website will not be able to detect it. It would just display the content as it is, whether its right or wrong.
L e t sc r e a t eo u rm u l t i l i n g u a ls i t es t e pb ys t e p
Fire up visual studio and create a new asp.net website. Once you have your website in the solution explorer, right click on the website and select Add asp.net folder option and create App_LocalResources folder. See the screen shot below:
F o l l o w e r s
Join this site
w ith Google Friend Connect
Members (2)
http://murlid05.blogspot.in/2012/10/creating-multilingual-website-english.html
1/6
3/6/2014
A b o u tM e
D Murli View my complete profile
Please notice that you need to select App_LocalResources folder, not App_GlobalResources folder. We created this folder because we will be storing our resource files in this folder. Resource files are the files in which we will add our data in the different languages.
A d dan e ww e bp a g et oy o u rw e b s i t e
Right click on your website and add a new web page. Lets name this page as MultiLingualPage.aspx. See the screen capture below:
A d dar e s o u r c ef i l et oy o u rp r o j e c t
What is a resource file and why is it needed ? Any project that you create have some resources associated with it. Your images, audio files, video files, text files etc that you use in your project are all known as resources for your project. In this particular case we need different files in which we will store our strings. I have created this multilingual website in English and Hindi. So i will create 2 resource files, one for English and the second one for Hindi. Microsoft has created .net to be culture sensitive. Many cultures in this world are supported by .net. When i say cultures i mean spoken languages. The default culture for .net is en-US, which is United States English. If we want to change the culture to Indian Hindi, we will write hi-IN. Similarly Indian Punjabi is supported, we will write pa-IN. All resource files are culture specific. If I add hi-IN to
http://murlid05.blogspot.in/2012/10/creating-multilingual-website-english.html
2/6
3/6/2014
By default this resource file will be considered for en-US culture. Next lets add a new resource file for Indian Hindi culture. See the screen shot below:
Thus we have 2 resource files in the App_LocalResources folder, one for en-US culture and the second one for hi-IN culture.
B u th o ww i l lt h ew e b s i t ec h a n g ei t sl a n g u a g e?
We display text using labels. This is how you add a label to your page. Text=Hello World > For this label you have fixed the text to Hello World , and that too in English. Now what ever you do you can not change the language for this label. Every time you run your website this label will display Hello World and that too in English. Now the trick to change the language for you asp.net website is not to provide text to your label directly. We will
http://murlid05.blogspot.in/2012/10/creating-multilingual-website-english.html
3/6
3/6/2014
Similarly for your Hindi resource file add the Hello World ! string in Hindi. See the screen shot below.
B u tm yk e y b o a r di si nE n g l i s h .H o wc a niw r i t eo t h e r l a n g u a g e s?
Well, Google is the answer. Google provides both translation and transliteration services. The demo site i have created contains text written in English and Hindi. I wrote the content in English and the used Google translation and transliteration both to get appropriate conversions. Below are the links for both these services. Google Translation Service : Click here Google Transliteration Service : Click here
L a s ts t e p ,h o wt oc h a n g et h ec u l t u r ef o rt h ew e b s i t e?
Put an asp.net DropDownList on your web page and provide it the following markup: AutoPostBack=True>
This drop down list has two options, one for English and the second for Hindi. The value for English selection is en-US and that for Hindi selection is hi-IN. The user can choose the language of his choice from here and we will set the culture of the website accordingly. The code for changing the culture for the website will be added to the Global.asax file, in the Application_BeginRequest event. See below: void Application_BeginRequest(Object sender, EventArgs e) {
http://murlid05.blogspot.in/2012/10/creating-multilingual-website-english.html
4/6
3/6/2014
W ea r ed o n e!
Now finally when you will run your site the user will be displayed the label in English by default. Then when he selects Hindi language from the drop down, we change the culture of the website in the Application_BeginRequest event. We set the culture to hi-IN and the web page automatically reads the Hindi resource file and displays the text in Hindi. Below are the screen shots of the demo application for this post, both in English and in Hindi.
Simple and smooth. You can download the code for this multilingual website and run it on your system to understand it even better. I have tried to explain quite in detail, but you might not get the real feel unless you download and run the code by yourself. Please post your queries as comments to this post in case you could not understand the concept even after running the website on your local machine. I will reply to your queries and help you understand the concept. Check the following link to see this multilingual site in action and also for downloading the source code. Hope the information provided in this post was useful. Please provide us your comments / suggestions / appreciations which would help us in providing even more useful posts on this blog. You can help us in sharing this information by clicking the facebook share button, facebook like button or the twitter tweet button below. Also you can share this information on social
http://murlid05.blogspot.in/2012/10/creating-multilingual-website-english.html
5/6
3/6/2014
2 comments:
1. cmsbuffet November 12, 2012 at 12:52 AM With multilingual websites taking over, more consumers are given an opportunity to buy any product or service they need. Multilingual web sites Reply
2.
mischel johnson May 2, 2013 at 5:56 AM This comment has been removed by the author. Reply
Comment as:
Google Account
Publish
Preview
Newer Post
Home
Subscribe to: Post Comments (Atom)
Older Post
http://murlid05.blogspot.in/2012/10/creating-multilingual-website-english.html
6/6