Asp.net & Sql server fundas with Rajat Jaiswal

April 24, 2009

Multi Language web site in 5 easy steps in 5 minutes

Filed under: Asp.net — indiandotnet @ 6:09 pm
Tags: , , ,

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

localization1

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

hindirex

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”

englieshrex

spanishrex

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.

pagedesign

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 :D

runningmode

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..

About these ads

25 Comments »

  1. Hi, nice post. I have been thinking about this issue,so thanks for posting. I will definitely be subscribing to your site.

    Comment by How I Lost Thirty Pounds in Thirty Days — May 3, 2009 @ 11:43 pm | Reply

  2. Hi, good post. I have been pondering this issue,so thanks for writing. I’ll certainly be coming back to your blog.

    Comment by How I Lost Thirty Pounds in Thirty Days — May 4, 2009 @ 1:36 pm | Reply

  3. 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.

    Comment by Kaushal — May 27, 2009 @ 6:30 am | Reply

    • 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 :)

      Comment by indiandotnet — May 28, 2009 @ 6:36 pm | Reply

  4. Hi There,

    Text in resx files for hindi is coming as square boxes.do we need to install any language pack or any configuration??

    Comment by Plaban — July 15, 2009 @ 10:05 am | Reply

  5. Hi Plaban,
    The Square box is hindi font.

    Thanks
    Rajat

    Comment by indiandotnet — July 15, 2009 @ 11:46 am | Reply

  6. Thanx dear for suggesting me another method to create hindi web side, acutly i use unicode to create hindi website

    Comment by Devesh — December 5, 2009 @ 7:22 am | Reply

  7. 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

    Comment by Vaivhav — December 17, 2009 @ 9:51 pm | Reply

    • 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

      Comment by indiandotnet — December 18, 2009 @ 4:02 am | Reply

  8. Hi, Thanks to you
    I have a question, what is the code of linked button in C#?

    Comment by Salem — January 17, 2010 @ 12:44 pm | Reply

  9. That is good indeed.
    Thanks

    Comment by Anuj — February 13, 2010 @ 2:53 pm | Reply

  10. 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…

    Comment by nilong — December 13, 2010 @ 9:56 am | Reply

    • Hi Nilong,
      Sorry for late response.
      It is your culture language which you set in session.

      Thanks
      Rajat

      Comment by indiandotnet — December 28, 2010 @ 6:44 am | Reply

  11. I have a question, what is the code of linked button in C#?

    Comment by IN.MG Domain — January 9, 2011 @ 5:58 pm | Reply

  12. Sir i wants that my project supports multiple languages
    for example
    user has selected hindi
    then our site matter convert into hindi.

    Comment by Anand Prakash Shukla — March 29, 2011 @ 6:42 am | Reply

  13. awesome man but tell me that does it means I need to create 15 different resource files and culture settings for 15 different languages?

    Comment by limo — May 21, 2011 @ 12:26 pm | Reply

  14. 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.

    Comment by Srini — August 29, 2011 @ 10:27 pm | Reply

    • Hi Raju,
      Please reply on my query then we will further go for this solution.

      Comment by indiandotnet — September 5, 2011 @ 4:57 am | Reply

  15. Hi Rajat Sir,
    i am vishal yadav , can u send me this source code on my mail id at svits.vishal@gmail.com

    Comment by vishal yadav — October 5, 2011 @ 10:48 am | Reply

  16. Hi , ,,,

    Can u post that application …..

    Please i have to learn

    Comment by Sajjad — March 31, 2012 @ 7:02 am | Reply

  17. 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

    Comment by faizan — April 27, 2012 @ 6:40 am | Reply

  18. i am using Ajaxpro script… so for this how can i add resources???

    Comment by Mohamed Umar — December 10, 2012 @ 1:43 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 220 other followers

%d bloggers like this: