Click here to Skip to main content
13,191,877 members (63,368 online)
Click here to Skip to main content
Add your own
alternative version


34 bookmarked
Posted 7 Sep 2009

Localizing ASP.NET MVC

, 7 Sep 2009
Rate this:
Please Sign up or sign in to vote.
I will examine how to localize ASP.NET MVC application using existing .NET Framework


Localization is the process of customizing your application for a given culture and locale. The .NET framework offers the following namespaces and classes to facilitate the localization.

  1. System.Globalization (The System.Globalization namespace contains classes that define culture-related information, including the language, the country/region, the calendars in use, the format patterns for dates, currency, and numbers, and the sort order for strings)
  2. CutureInfo provides information about a specific culture.
  3. The System.Resources namespace provides classes and interfaces that allow developers to create, store, and manage various culture-specific resources used in an application.

In this article, I will examine how to localize ASP.NET MVC application using existing .NET Framework. To create a new MVC project, see ASP.NET MVC application structure. Now, I will create a App_GlobalResources folder that will have the application resource files. To create a resource file in App_GlobalResources folder, follow these steps:

  1. Right-click your project –> Add –> Add ASP.NET Folder –> App_GlobalResources
  2. Right-click App_GlobalResources –> Add –> New Item –> Resources file

I will create two resource files English and French respectively. Now, I will change the "Access Modifier" settings to "Public" as shown below:

localize1.jpg - Click to enlarge image

Using the Code

Now I can access the resource setting in a strongly typed way as shown below in my view:

The easiest way to determine the visitor's preferred culture is to add culture="auto" and uiCulture="auto" in web.config as shown below:

<globalization culture="auto" uiCulture="auto"/>

However, this approach will not work when rendering a view using a different view engine or if the client setting is invalid. So I will assign the given culture in a global.asax as shown below:

protected void Application_BeginRequest(object sender, EventArgs e)
    CultureInfo culture = new CultureInfo("fr-CA");
    Thread.CurrentThread.CurrentCulture = culture;
    Thread.CurrentThread.CurrentUICulture = culture;

This will make sure that the current thread will apply the given culture. Now I will run the project and it will render a view as shown below:



In this article, we examined how to localize ASP.NET MVC applications using existing .NET Framework.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Farooq Kaiser
Software Developer (Senior)
Canada Canada
12+ years of complete software development life cycle experience for web based applications and multi-tier client-server desktop, primarily using LINQ, WCF, WWF, C#, ASP.NET, XML, XSLT, AJAX, Winforms,Visual Basic, JavaScript, JQuery, Google APIs, C++, VB.NET, C, ATL/COM, Open XML. Extensively involved in the requirement analysis, feasibility study, conceptualization, planning, architecture/design, configuration, development, quality assurance, implementation and release of the software products.

You may also be interested in...

Comments and Discussions

Generalengrossing Pin
Nuri YILMAZ22-Dec-10 1:55
memberNuri YILMAZ22-Dec-10 1:55 
GeneralMy vote of 1 Pin
Andrei Rinea14-Sep-09 22:24
memberAndrei Rinea14-Sep-09 22:24 
GeneralMy vote of 2 Pin
tec-goblin14-Sep-09 22:21
membertec-goblin14-Sep-09 22:21 
Indeed too simple. You could advance to localResources (in contrary to global resources, where you will soon have too many strings), auto-generated resource files by visual studio, changing languages, resource-based html helpers etc etc.
GeneralMy vote of 1 Pin
Makassi14-Sep-09 10:49
memberMakassi14-Sep-09 10:49 
GeneralMy vote of 2 Pin
tretyak8-Sep-09 11:09
membertretyak8-Sep-09 11:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171017.2 | Last Updated 7 Sep 2009
Article Copyright 2009 by Farooq Kaiser
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid