Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET - MVC 3: Localization

I am about to implement localization for my MVC3 web application. Googling my way through large amounts of ways to do it, I was left unsure which way to implement this. I found few ways how to do it:

First option I found was to use App_GlobalResources and ViewData and culture select with Map Routing. (Link)

Second was to make a separate Resources folder in my project and structure it like Model and View folders. Then create the resource files in those folders. To use those resource strings would be like using the Viewbag. Then edit the Global.asax to handle culture changing and create a partial view to allow changing cultures. The instructions to do this are very thorough so this might be the best bet. (Link)

Third was to use DisplayAttribute and resx-files. This one was a bit hazy, I could not find the sort of information so that I could grasp how this actually is implemented and its restrictions. (Link)

Fourth was to create a custom class to handle resources. This seemed pretty fancy and easy to implement and use but no real information was found if it actually worked. (Link)

Then I found a post that warned about using the App_GlobalResouces and App_LocalResources. (Link)

After going through possible ways of doing localization. I could not find a way which was universally approved or accepted. This left me pondering, which of these, or some I didn't find, would be the best way to implement localization in ASP.NET MVC3?

like image 436
Esa Avatar asked Jun 07 '11 12:06

Esa


People also ask

How ASP.NET application are localized?

To opt-in to localization, we need to modify our Startup file. We'll be registering a few services, configuring options, and registering middleware. All steps that are common-place for additions in an ASP.NET application. Starting in our ConfigureServices method, we need to make a call to AddLocalization .

How will you localize URL in MVC application?

To offer a website in multiple languages using ASP.Net we simply need to add some resource. resx files to our project and voilà. Based on the language of the browser, IIS will match the localization resource.

How globalization is implemented in ASP.NET MVC?

Image is used from: Globalization. In Visual Studio 2013 select "File" from the menu and inside that select Project and then a New Dialog will popup with the name New project. Inside that select Templates then select Visual C# and then inside that select web then select ASP.NET MVC 4 Web Application.


1 Answers

Then I found a post that warned about using the App_GlobalResouces and App_LocalResources. (Link)

I found that post extremely useful. The method explained there is very clean. Here is a snippet of my newly created index view using that method:

@using Resources.Index @{     ViewBag.Title = "Index"; }  <h1>@Index.Title</h1> 

I don't think there is a definitive do-it-this-way-or-else method, so going for the cleanest method seems to me like a good deal.

like image 63
Tjaart Avatar answered Sep 22 '22 14:09

Tjaart