Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Photos | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » ASP.NET & Web Forms » Arabization: Localization/Globalization in ASP.Net 2.0

Arabization: Localization/Globalization in ASP.Net 2.0

In order to reach global market for any successful product, it is necessary that product supports maximum regional languages. To have support different languages, it is required that while developing product, the concept of localization / globalization utilized.

Author Rank:
Total page views :  24708
Total downloads :  690
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
MultiLingual.zip
 
Become a Sponsor

There are many tutorials which explain you about localization / globalization concept. In this article I just tryed to explain every single point from the developer/programmer point of view.

Let me brief you about Resource files.

  1. "aspx.resx" (resource) files: Resource files are xml files, which stores string, file paths (image), which are required to translate in to other languages.
  2. "App_GlobalResources": You can keep files which need to be accessed throughout the application. So in our application I have kept "TextDirect" & "EmailFormat" which required to access in maximum pages. In short common strings.
  3. "App_LocalResources": Local resources are associated with the single web pages, In this folder I have kept lables and strings which are specific to particualt aspx page it self.

Note: Since I am showing this in english and arabic. So every aspx page will have two different resource files.

For Example:

I have "Registration.aspx" page, for this page I had made files as follows:

  1. Registration.aspx.ar.resx (for arabic content to be stored).
  2. Registration.aspx.resx (for english content to be stored).

The above files are local, now letus consider files which can be accessed globally as.

  1. MulResource.resx
  2. MulResource.ar.resx

These files are used for storing "EmailFormat" & "TextDirection" which is common for most of the pages.

To create a resource file manually:

Make sure that your Web site has a folder in which to store the resource file by doing one of the following:

If you are creating a global resource file, you must have a folder named App_GlobalResources. To create the folder, in Solution Explorer, right-click the name of your Web site, click Add Folder, and then click App_GlobalResources Folder. There can only be one of these folders in an application, and it must be located at the root of the application.

If you are creating a local resource file, you must have a folder named App_LocalResources. To create the folder, in Solution Explorer, right-click the name of your Web site, click Add Folder, and then click App_LocalResources Folder. There can be many of these folders in an application, and they can be located at any level in the application.

To create a resource file, right-click the App_GlobalResources or App_LocalResources folder, and then click Add New Item.

Global resource files must be in the App_GlobalResources folder. If you try to create a .resx file outside of this folder, Visual Web Developer prompts you to create it in the folder.

Glbalization:

It is process by which you can develope application / program so that it can be used by the various regions/cultures. Let us consider that you have made a product called as "Shopping Cart" and you want to sell it to different regions, since it is online say arabic people should able to read the info in Arabic & English people should read it in English. To achive this we have to use something called as localization

Localization:

It is process of using specific regional/cultural info so that your program uses local language.

Culture:

Every region has different language and language is depend on different geographical location.

For example: "ar-EG" ar is the code for arabic language & EG means this language is spoken in Egypt country/region so "ar-EG" sets for Arabic-Egyption. Similarly "en-US" stands for English-United State.

Note: In IE the user can change the culture by going to Internet Options->General->Languages. For this to work, we need to set both the Culture and the UICulture to auto and enableClientBasedCulture = true

Setting Page Culture:

You can set the page culture by two ways:

  1. <globalization enableClientBasedCulture="true" culture="ar-EG" uiCulture="ar-EG"/>

  2. Setting culture by programmatically.

protected override void InitializeCulture()
{
    //string culture = Request.Form["ddSelLanguage"];
    string culture = Session["Language"].ToString();
    if (string.IsNullOrEmpty(culture))
        culture = "Auto";
    //Use this
    UICulture = culture;
    Culture = culture;
    //OR This
    if (culture != "Auto")
    {
        System.Globalization.CultureInfo MyCltr = new System.Globalization.CultureInfo(culture);
        System.Threading.Thread.CurrentThread.CurrentCulture = MyCltr;
        System.Threading.Thread.CurrentThread.CurrentUICulture = MyCltr;
    }
    base.InitializeCulture();
}
 

Code:

In "Default.aspx" file I have a drop-down by which user can select specific language, i have Arabic and English languages and by default "Auto" is set. I have used Auto-postback property of the drop-down & even you can make use of submit button for the same.

Once you got the selected language you can hold that value in the session as explained in the above code.

Session["Language"] = Request.Form["ddSelLanguage"];

While overriding the InitializeCulture() method you can assign this to the culture variable.

In this application i have tryed to explain with two different forms:

  1. User registration form.
  2. Send Email (In which I have also explained that how can we make use of built-in asp.net validation controls).

And on both the pages i have shown as we can switch on different pages by making use of <asp:HyperLink>.

Now let us have a look at "Registration.aspx" page code.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Registration.aspx.cs" Inherits="Registration" meta:resourcekey="RegResource" %>

This code is preety much similar with the code which get generated normally for any aspx page, only difference is that:

meta
:resourcekey="RegResource"

Here I want to explain in little depth, the concept of storing values like key-value pair and accessing values in the aspx page. Forexample if you refer to "Registration.aspx.resx" & "Registration.aspx.ar.resx" pages you will notice that
A resourceKey "RegResource.Title" has value "Registration" similarly in the other language. "RegResource.Title" has  value, which is directly accessed as shown above.

<
html id="Html1" runat="server" dir='<%$ Resources:MulResource, TextDirection %>' xmlns="http://www.w3.org/1999/xhtml">

In the above <html> tag it should have runat="server" attribute or it will give you error use literal runat="server" .

As i have already explained you about the global & local resources, in the above <html> we have used dir='<%$ Resources:MulResource, TextDirection %>'  attribute, now let us go little in dept for this, many of you must be aware of "DIR" attribute, it is nothing but the direction or the text in the page by default it is LTR (left to write) to have arabic type of appearance of the page we have to use it as "RTL". In short this act as common for all the pages either LTR or RTL so i have two global resource files as:

  1. MulResource.resx
  2. MulResource.ar.resx

In which you will find "TextDirection" ResourceKey and it's value associated with it, which is used in the above code.

I think so far so clear?

Now let us see how we can access the value of different labels in our project.

For example: On the registratio page i have label called as "lblFirstName" and it's values are stored in the corrosponding resource files viz.

  1. Registration.aspx.resx
  2. Registration.aspx.ar.resx

Here is code to make use of the same.

<asp:Label ID="lblFirstName" runat="server" meta:resourcekey="lblFirstName"></asp:Label>

Note: None of the labels have assigned any default value, label get values assigned at runtime depend on the selected language on the default page.


Login to add your contents and source code to this article
 About the author
 
Munir Shaikh
Munir is MCP in Microsoft .NET Framework 3.5, Windows Communication Foundation
Appl ication Developmen, software Developer/ project lead with 9 Yrs development experience who works on IT projects mainly for Microsoft and some open source technologies. Most of these projects have been intranet based web applications / sites with SQL/Oracle as back-end. Currently he  is focusing more on Silverlight, WCF & WPF development. He had worked on payment gateway implementation. He is experienced in Insurance, Supply Chain management, Trading, Real-Estate & currently Legacy modernization domain.
Apart from this he has implemented on CMMi L3 for organization and has good understanding of process. He has also involved in consulting activities like Architecture Review, Project Plan, HLD, LLD, Risk Management etc....
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010 Professional
Microsoft Visual Studio 2010 Professional will launch on April 12, but you can beat the rush and secure your copy today by pre-ordering at the affordable estimated retail price of $549 (US). Pre-order now.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
 
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
MultiLingual.zip
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Become a Sponsor
 Comments
question by ahmad On May 30, 2007
how to write arabic direct in text box without press on alt+shift please quick because i am developer in Raed Arabi company in jordan (middle east)
Reply | Email | Delete | Modify | 
how to add Russian,korean and Chinesa languages by Sudha On July 2, 2007
This Is very urgent
Reply | Email | Delete | Modify | 
Re: how to add Russian,korean and Chinesa languages by Munir On July 5, 2007
Hi, zh-CN is the culture code for Chinese in China if you have default.aspx file in your project then under "App_Localization" folder you should have default.aspx.hz-CN.resx file, similarly for the rest all the languages E.g for Russian you will have culture code as "ru-RU" & for Korean language it should be "ko" for more culture information have following link Culture Code Detail information Enjoy! >>Munnamax
Reply | Email | Delete | Modify | 
Explanation of Implementing Globalization Practically by DotNetGuts On August 23, 2008
Explanation of Implementing Globalization Practically http://dotnetguts.blogspot.com/2007/02/ease-of-applying-globalization-and.html
Reply | Email | Delete | Modify | 
Explanation of Implementing Globalization Practically by DotNetGuts On August 23, 2008
Explanation of Implementing Globalization Practically http://dotnetguts.blogspot.com/2007/02/ease-of-applying-globalization-and.html
Reply | Email | Delete | Modify | 
Explanation of Implementing Globalization Practically by DotNetGuts On August 23, 2008
Explanation of Implementing Globalization Practically http://dotnetguts.blogspot.com/2007/02/ease-of-applying-globalization-and.html
Reply | Email | Delete | Modify | 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 2010  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.