Multiple languages ​​in an ASP.NET MVC application?

What is the best way to support multiple languages ​​for an interface in an ASP.NET MVC application? I have seen people use resource files for other applications. Is this the best way?

+62
asp.net-mvc internationalization multilingual
Aug 6 '08 at 21:43
source share
6 answers

If you use the default view engines, local resources work in views. However, if you need to capture resource strings as part of a controller action, you cannot get local resources and must use global resources.

This makes sense if you think about it, because local resources are local on the aspx page and in the controller, you haven't even chosen your view.

+40
Aug 07
source share

I found this resource to be very useful

This is a wrapper around HttpContext.Current.GetGlobalResourceString and HttpContext.Current.GetLocalResourceString , which allows you to call resources like this ...

// default global resource Html.Resource("GlobalResource, ResourceName") // global resource with optional arguments for formatting Html.Resource("GlobalResource, ResourceName", "foo", "bar") // default local resource Html.Resource("ResourceName") // local resource with optional arguments for formatting Html.Resource("ResourceName", "foo", "bar") 

The only problem I encountered is that the controllers do not have access to local resouce strings.

+21
Sep 16 '08 at 0:00
source share

Yes, resources are still the best way to support multiple languages ​​in the .NET environment. Because they are easy to reference and even easier to add new languages.

 Site.resx Site.en.resx Site.en-US.resx Site.fr.resx etc... 

So you are still using resource files.

+3
Aug 6 '08 at 21:48
source share

An Orchard project uses a shortcut method called "T" to perform all line feeds on a page. So you will see tags with @T ("A String to Translate").

I intend to see how this is implemented behind the scenes and potentially use it in future projects. The short name keeps the code cleaner, since it will be used a lot.

What I like about this approach is the original line (in English in this case) is still easily visible in the code and does not require searching in the resource tool or elsewhere to decode what should be here,

See http://orchardproject.net for more details.

+2
Apr 13 '11 at 18:44
source share

Some of the other solutions mentioned as an answer do not work for the released version of MVC (they worked with previous versions of alpha / beta).

Here is a good article describing a way to implement localization that will be strongly typed and will not interrupt unit testing of controllers and views: a localization guide for MVC v1

+1
09 Oct '09 at 14:24
source share

This is another option and you will have access to CurrentUICulture in the controller:

Check MVC3-multi-language

0
Jul 13 2018-12-12T00:
source share



All Articles