Multi language supported web site in ASP.NET

No.of Views2425
Bookmarked0 times
Downloads 
Votes0
By  ashraf   On  16 Feb 2010 03:02:44
Tag : ASP.NET , How to
Multi language supported web site in ASP.NET
emailbookmarkadd comments print

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

 It is easy to develop multi language supported web site using ASP.NET . Just follow that step by step.

1. Take a new web site
2. Add “App_GlobalResources” from ASP.NET folders
3. Take a *.resx file (Strings.resx)
4. Enter Name and values
5. Make different *.resx file for different languages and name like that Strings.en-US.resx (for US english), Strings.fr-FR.resx (for French). Make as many language file you needed.
6. Now time for calling and using language from web page.

You web site Solution Explorer will look like that

Image Loading

 

Default.aspx file will look like that

<asp:Label ID=”lblName” runat=”server” Text=”Label”></asp:Label>
<asp:Label ID=”lblDesc” runat=”server” Text=”Label”></asp:Label>
<asp:Label ID=”lblComments” runat=”server” Text=”Label”></asp:Label>
<asp:LinkButton ID=”lnkEnglish” runat=”server” OnClick=”lnkEnglish_Click”>English</asp:LinkButton>
<asp:LinkButton ID=”lnkFrench” runat=”server” OnClick=”lnkFrench_Click”>French</asp:LinkButton>

Codes of Default.aspx.cs

private ResourceManager rm;
protected void Page_Load(object sender, EventArgs e)
{
CultureInfo ci;
if (!IsPostBack)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
rm = new ResourceManager("Resources.Strings", Assembly.Load("App_GlobalResources"));
ci = Thread.CurrentThread.CurrentCulture; LoadData(ci);
}
else
{
rm = new ResourceManager("Resources.Strings", Assembly.Load("App_GlobalResources"));
ci = Thread.CurrentThread.CurrentCulture; LoadData(ci);
}
}

protected void lnkEnglish_Click(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
LoadData(Thread.CurrentThread.CurrentCulture);
}

protected void lnkFrench_Click(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
LoadData(Thread.CurrentThread.CurrentCulture);
}

public void LoadData(CultureInfo ci)
{
lblName.Text = rm.GetString("EventName", ci);
lblDesc.Text = rm.GetString("EventDescription", ci);
lblComments.Text = rm.GetString("EventComments", ci);
}

 

Conclusion

In this article i ahve given details to create website with multilanguages.it's means the client can view interface text are on in different languagess.

 
Sign Up to vote for this article
 
About Author
 
ashraf
Occupation-Not Provided
Company-Not Provided
Member Type-Fresh
Location-Not Provided
Joined date-01 Aug 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top