C#,vb.net,MVC,Jquery,javascript,jscript,vbscript,html,vb,sharepoint,COM,WPF,WCF,Wwf,Asp,Asp.net,questions & answers,

Latest in Sports

Thursday, June 28, 2012

Implementing Multilingual Application using ASP .NET 2.0 using c#

Implementing Multilingual using ASP .NET 2.0:

Below are the few steps to make your application to have multiple language support:
  1. Create two base classes for web page and usercontrol each, which would be inherited from the “System.Web.UI.Page” and “System.Web.UI.UserControl” respectively.
Code snippet for the PageBase class:
Note:- If your application does not have any user control then UserControlBase class need not be created. If UserControlBase class needs to be created, it can be created similar to the above code snippet. The only difference the UserControlBase class would have is the parent page it would be inheriting to (i.e. System.Web.UI.UserControl).
  1. All the web pages and the user controls in the application would be inherited from the respective base classes which would have the basic implementation for setting the current language and loading the available global resources. The web page / the user control would have to call the “base.SetLanguage("en-US")“ method in order to set the current language and have to use the “base.ResManager“ property to set localized texts for individual controls on the web page / the user control.
Code snippet for the Default web page:

The resource files can be created under “App_GlobalResources” folder under root directory. In the above code sample we have taken example by assuming that “App_GlobalResources” folder has three resource files:

-       ControlsTexts.resx
This resource file is considered as a neutral resource file. If the requested text is not found under the localized resource file, the same text will be retrieved from the neutral resource file. For instance, if the application supports only en-US (English) and hi-IN (Hindi), and if the user’s culture is set to en-GB (Brithish Engish), then all the requests for the resources will be redirected to the neutral resource file since the ControlsTexts.en-GB.resx is not present in “App_GlobalResources” folder.

-       ControlsTexts.en-US.resx
This resource file is considered as US English language localized file and is utilized when the user’s locale is set to en-US or user click on “btnEnUS” button. All the resources would be picked from this resource file in such scenario.

-       ControlsTexts.hi-IN.resx
This resource file is considered as Hindi language localized file and is utilized when the user’s locale is set to hi-IN or user click on “btnHindi” button. All the resources would be picked from this resource file in such scenario.

The Default.aspx page is assumed to have following controls:
-       Two Buttons controls, “btnEnUS” and “btnHindi”, on clikck of these buttons respective events will be triggered as shown in the above code snippet.
-       Three Label controls, “lblFirstName”, “lblMiddleName” and “lblLastName”.

Thanks to Ghandi,

 

1 comment:

  1. I thought finding a company that will help me provide all the services that all small business need is a tough one. Thank you for enlightening us about implementing multilingual application.

    Multilingual websites

    ReplyDelete