Hello friends,
Here I am with a new topic Localization Globalization. Most of the time our client require website which support multi language so in that case we have to do some extra effort. Asp.net provides simplest way of how to do this. So friends I am explaining you 5 minimum steps which help us to make a website multi language.
I am talking my favorite 3 languages Hindi, English, Spanish.
So here we go
Step 1:- The first basic step you have to create a resource file which will be your default resource file for your project.
To create resource file you have to open your file then select menu option Tool –> Generate Local resource as shown in below fig
As you done with this option what you will see that in your solution explore a new folder is added with name “App_LocalResources” which having the file name extension “.resx” means suppose if you have open default.aspx file and you say generate local resource then you will get “default.aspx.rsex” in app_LocalResouce Folder. This will be your default Resource file.
When you open this file you will find. Name & Value & comment column.
Here Name is related with your page control and what should be the value for this controls will be exist in your value column.
For me by default it’s English so there is no issue for English.
Step 2:- Create new resource file for Hindi. For this we will do just copy and paste existing resource file and rename that file and replace the value which we want in Hindi or Spanish. See below fig for it
The things to remember here that when you saving particular language file then the language code should be there for example if I am using Spanish language then my file name will be “Default.aspx.en.resx”
And for Hindi my file name will be “Default.aspx.hi.resx”
Step3:- when you see your file default.aspx then you will find there is extra text with each of your control which is resource key.
For example see below lines here we have resource key lblWelcomeMessageResouce1 this should be present in our resource file. At run time dot net get the value from this key.
<asp:Label ID=”lblWelcomeMessage” runat=”server” Text=”Hello and welcome “ meta:resourcekey=”lblWelcomeMessageResource1″></asp:Label>
And for drop down we having following code
<asp:DropDownList ID=”ddlLanguage” runat=”server”
meta:resourcekey=”ddlLanguageResource1″>
<asp:ListItem Text=”English” Value=”en-US” Selected=”True”
meta:resourcekey=”ListItemResource1″></asp:ListItem>
<asp:ListItem Text=”Hindi” Value=”hi-IN” meta:resourcekey=”ListItemResource2″></asp:ListItem>
<asp:ListItem Text=”Spanish” Value=”es-MX” meta:resourcekey=”ListItemResource3″></asp:ListItem>
</asp:DropDownList>
Step 4: I have design my page as shown below.
We have to look for two basic namespace here one is Resource and another is globalization.
Once you done with the above step now you have to set the culture according to your chosen value from drop down.
For that we have to write following code
Protected Overrides Sub InitializeCulture()
Try
Dim _culture As String = Session(“Language”)
If _culture <> String.Empty Then
Dim ci As New System.Globalization.CultureInfo(_culture)
System.Threading.Thread.CurrentThread.CurrentCulture = ci
System.Threading.Thread.CurrentThread.CurrentUICulture = ci
End If
MyBase.InitializeCulture()
Catch ex As Exception
Throw ex
End Try
End Sub ‘InitializeCulture
Its just override your base class seating. In session we are putting value we have selected in drop down.
On button click event we assign the value (selected dropdown value) in the session.
In this way we get multi language web page.
Step 5:- Just run it 😀
In this way we have finished our minor task
You can download code from http://www.indiandotnetmultilanguagework.tk/
In next few days I will come back with more solid presentation.
Till than
Do Take Care your self
And enjoy coding..
Hi, nice post. I have been thinking about this issue,so thanks for posting. I will definitely be subscribing to your site.
Hi, good post. I have been pondering this issue,so thanks for writing. I’ll certainly be coming back to your blog.
Hi,
Very useful post,but i have one question that,how can insert value field on hindi resource file which is appropriat with “Hi and Hello” word,how can we identify that this text display “Namaste aur apka swagat hai” in hindi language.
Thanks.
Hi Kaushal,
What i did currently i used google hindi translator just typed “Namaste aur aap ka swagat hai” in resource file.
now resource file having resource key or you can say a id which identify for which control we are writing the test.
in this manner it handle.
if you have further query just post a comment with detail.
thanks
Rajat 🙂
Hi There,
Text in resx files for hindi is coming as square boxes.do we need to install any language pack or any configuration??
Hi Plaban,
The Square box is hindi font.
Thanks
Rajat
Thanx dear for suggesting me another method to create hindi web side, acutly i use unicode to create hindi website
Hi, nice post
i m developing a hindi web site i need help how to handel unicode fonts for hindi web site please help.
asp.net + c# (Web Site)+ MSSQL 2005
the Text Field we have taken as Nvarcahr
pls helpfor the above.
From
Vaibhav
Hi Vaibhav,
Thanks for your comment.
for mutli language save in sql server firstly you have to change collation according to your need secondly you have to change data type to NVARCHAR
Thanks
Rajat
Hi, Thanks to you
I have a question, what is the code of linked button in C#?
That is good indeed.
Thanks
Dim _culture As String = Session(“Language”)
bt what is language..means this object will never use in all project….
and how to pass on button event..pls…
Hi Nilong,
Sorry for late response.
It is your culture language which you set in session.
Thanks
Rajat
I have a question, what is the code of linked button in C#?
Sir i wants that my project supports multiple languages
for example
user has selected hindi
then our site matter convert into hindi.
Hi Anand,
you can check https://indiandotnet.wordpress.com/2010/09/05/asp-net-website-in-hindi-or-other-native-language-with-simple-steps/
you want like this.
Thanks Rajat
awesome man but tell me that does it means I need to create 15 different resource files and culture settings for 15 different languages?
Hi Rajat ,
I am working on a Project where our web application supports multi language for 40 different languages. I want to know how to validate the data using Coded UI Tests.
Hi Raju,
Please reply on my query then we will further go for this solution.
Hi Rajat Sir,
i am vishal yadav , can u send me this source code on my mail id at svits.vishal@gmail.com
Hi , ,,,
Can u post that application …..
Please i have to learn
Hi, good explanation,i hv some query
>does i need to create resource file for each page
>wht if my data is coming from database, how can i fill in drop down according to current language set.
>if hindi language is selected and user have to fill his information in text box , how to show entering text in hindi.
plz reply me i’ll be very thankful.
faizan
Hi,
Please refer https://indiandotnet.wordpress.com/2010/09/05/asp-net-website-in-hindi-or-other-native-language-with-simple-steps/
Good one
Instead of Local Resources i have used Global Resources
heres the link
http://satindersinght.blogspot.in/2012/06/create-website-for-multilanguage.html
And for database you can set nvarchar as datatype
i am using Ajaxpro script… so for this how can i add resources???