Beruflich Dokumente
Kultur Dokumente
Sign up for our free weekly Web Developer 10,440,381 Newsletter. members (64,550 online)
home
articles
quick answers
discussions
features
community
help
Next
Article Browse Code Bugs / Suggestions Stats Revisions Alternatives Comments & Discussions (18)
About Article
How Globalization and Localization work in ASP.NET Type Article CPOL 23 Feb 2012 59,795 3,990 53 times
Rate this:
Introduction
This article is aimed at understanding how Globalization and Localization work in ASP.NET.
Background
A few days ago, I saw a TV commercial that said that "Even the smallest business can go multinational". This is very true specially in case of software business where guys operating from their store room provide services to users on the other side of the globe. If we need our website to be designed in such a way that it caters to the need of users from across the planet, then perhaps it is a good idea to understand and implement G l o b a l i z a t i o nand L o c a l i z a t i o nin our application. ASP.NET framework makes it pretty easy to implement these features by providing a lot of boilerplate functionality to the developers. Before starting, let's get these two terms straight. G l o b a l i z a t i o nis the process of designing the application in such a way that it can be used by users from across the globe (multiple cultures). L o c a l i z a t i o n , on the other hand, is the process of customization that we do to have our application behave as per current culture and locale. These two things go together.
Top News
News on the future of C# as a language
Get the Insider News free each
http://www.codeproject.com/Articles/334820/Using-Globalization-and-Localization-in-ASP-NET
1/6
3/6/2014
Related Videos
Right now, I am populating these labels at design time, but if I have to support multiple cultures then I will have to get them from a local resource file. Visual Studio provides a mechanism for creating the local resource file from a given web page. This can be done by viewing the page in design view and then " T o o l s > G e n e r a t eL o c a lR e s o u r c e s " . This will create a App_LocalResources folder and generate a local resource file for this page and start taking the text values for all the labels from that resource file. (All Local resource files reside in App_LocalResources and all the global resource files are in App_GlobalResources folder.
Related Articles
New in Visual Studio 2008 (Local and Global Resources) Globalization and localization demystified in ASP.NET 2.0 Declarative ASP.NET globalization Deep talk on Cultures and languages with ASP.NET and SQL ASP.NET Localization (Quick Reference) ASP.NET and Globalization
If we look at the resource file, it contains text for all the controls of the page.
Always close your cursor Page Localization AJAX Localization and Globalization Internationalization A Beginner's Guide to ASP.NET Application Folders
Collapse | Copy Code
The controls inside the page are now using the resource file to get its contents:
< a s p : L a b e lI D = " l b l W e l c o m e "r u n a t = " s e r v e r "m e t a : r e s o u r c e k e y = " l b l W e l c o m e R e s o u r c e 1 " > < / a s p : L a b e l >
ASP.NET 2.0 Globalization & Localization solution Localization (Globalization) of RDLC reports in ASP.NET applications Localizing ASP.NET MVC Globalization & Localization Small and Reliable C++ HTTP Server with Complete ASP.NET Support Quick Overview: Temporary Tables in SQL Server 2005 Globalization Best Practices Four real world uses of Partial classes and Partial methods DotNetNuke Resources keys
Now we need to create the local resource files for this page so that the page will take the text from respective files based on current users culture. The format for having the multiple resource files for a page is: PageName.aspx.languageId-cultureId.resx. If the resource file for any laguage-culture combination is not found, then the default resource file will be taken. If we want to display this web page in hindi-Indian, then we need a resource file Default.aspx.hi-in.resx.
Now if we run our page, we will not see any changes to test the changes. To test the changes, we need to set the default language of our browser to H i n d i I n d i a n . I did that for my IE.
Related Research
In-The-Wild Testing: How to Ensure Your Apps Work in the Real World
http://www.codeproject.com/Articles/334820/Using-Globalization-and-Localization-in-ASP-NET
2/6
3/6/2014
Fine-Tuning the Engines of SMB Growth: 4 strategies for growing your business
Learn Agile: Ten Tips for Launching and Testing High Quality Apps for the American Market
Now, when I run the page, the ASP.NET detects that user setting specifies language and region as Hindi and Indian respectively so it start pulling the text from our newly created resource file. If I do the same process for Spanish, then since the resource file for Spanish is not present, the default resource file will be taken. If we need support for Spanish, then we need to create a separate resource file for Spanish.
The Essential Guide to Mobile App Testing: Tips for Developers in USA & Canada
But it not a good idea to trust the users browser and system settings to get the culture specific information. It is always a good idea to provide the user an option to change the language and culture for the website. So let us provide the user with a dropdown where he can select the current language. To accomplish this, what we need to do is to override the I n i t i a l i z e C u l t u r efunction and set the U I C u l t u r eto the user selected language.
Collapse | Copy Code
http://www.codeproject.com/Articles/334820/Using-Globalization-and-Localization-in-ASP-NET
3/6
3/6/2014
This will give the user an option to switch languages dynamically. But there is one thing to notice which I circled in red. The UI is displayed in Hindi but the date format is not in Indian format. To do that, we need to set the C u l t u r eto selected culture so that the date, currency and other region specific format settings will also take effect.
Collapse | Copy Code
} b a s e . I n i t i a l i z e C u l t u r e ( ) ;
Now we have a small web page that is capable of being displayed in English and Hindi. To sum up, it is important to understand that Resource file is the key to have globalization and localization. The Global resource files contains text that is common to all the pages in the website and any control from any page can be bound to it. Local resource file is page specific. We need separate resource file for each supported culture. It is always a good idea to have a default resource file too. Finally, we should never trust users browser settings and provide the "Language/Culture Change" option on our website too.
Points of Interest
There are few important things to be understood when we are targeting our website to multiple cultures. When we are targeting multiple cultures, we cannot assume anything about the structure and layout of web page. The reason these things are important is because translation for even small text in English could be very lengthy in other languages. So it is always a good idea to follow the standard guidelines when we implement globalization. No absolute positioning of controls Use fluid layout with forms No absolute size of controls Try to arrange controls in a table I think, after this exercise, we can now start working on globalizing any website. It sure does take time to implement this stuff but ASP.NET relieves a lot of burden from the developer by providing some "must-have-always" functionality in place.
History
23 Feb 2012: Using Globalization and Localization in ASP.NET
http://www.codeproject.com/Articles/334820/Using-Globalization-and-Localization-in-ASP-NET
4/6
3/6/2014
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Article Top
how to embeded hindi font in web application and support to all Browsers Request.Form["DropDownList1"] is always null How to create a globalization page without using the Internet Options to change the language? how to localize default.aspx , if default.aspx is in other folder instead of root folder Translate Dynamic Data Using Culture My vote of 4 My vote of 5 Article of the Day on Microsoft's site Not working with Chrome
FaizySoftTech
29-Sep-13 22:40
Rohit More
3-Jul-13 20:58
1-May-13 19:46 7-Dec-12 22:51 6-Dec-12 19:43 26-Nov-12 23:53 16-Oct-12 20:05
http://www.codeproject.com/Articles/334820/Using-Globalization-and-Localization-in-ASP-NET
5/6
3/6/2014
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
Permalink | Advertise | Privacy | Mobile Web01 | 2.8.140305.2 | Last Updated 23 Feb 2012 Layout: fixed | fluid Article Copyright 2012 by Rahul Rajat Singh Everything else Copyright CodeProject, 1999-2014 Terms of Use
http://www.codeproject.com/Articles/334820/Using-Globalization-and-Localization-in-ASP-NET
6/6