robin
robin

Reputation: 497

ASP.NET MVC 5 Internationalization

I'm starting a new solution in ASP.NET MVC5 and I'll have to implement internationalization for the whole views.

The best article I found so far that explains how to well implement ASP.NET MVC 5 Internationalization was this one. I also read this one.

Anyway I still have some questions that I'd like the ask here in order to make sure about the best practices of internationalization which ones I still haven't found clearly answers on web.

  1. Where should I put my local (resources for a specific view) .resx files? App_LocalResources folder? ItemView folder with all the other files? Where exactly and why?
  2. How can I access my local resources values? Should I put them over the same App_GlobalResources namespace's .resx files (namespace Resources)?

Thank you in advance.

Upvotes: 1

Views: 2727

Answers (2)

veratti
veratti

Reputation: 570

According to MSDN, local resources are a concept relative to .aspx views.

In MVC, it is recommended to avoid App_GlobalResources and App_LocalResources. A great answer/explanation regarding this can be found here.

Alternatives to App_*Resources include:

Properties > Resources

enter image description here

Resources Folder

enter image description here

Resources Project

enter image description here

Upvotes: 1

Stefano Losi
Stefano Losi

Reputation: 729

You can simply put your resource files in a custom folder. I created a "resources" folder and it works like a charm.

My project

To access values, here an example for an action link:

@Html.ActionLink(Resources.Labels.Archivio, "Archivio", "Home")

Note you don't specify the Language, because MVC takes the locale loaded into the current thread

        Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
        Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

Upvotes: 0

Related Questions