Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localization in ASP.NET 5 MVC 6

There is already 7th beta version of ASP.NET 5, in which they say localization features are done. How can I use localization to write multi-language applications in asp.net 5 mvc 6 with visual studio 2015? Is there any working example project for beta 7 version? I have already searched and found many examples but they no more work because the code has been changed since that. Can I still use .resx files (because visual studio does not auto-generate Designer.cs files any more) or are there any newer or alternative methods they suggest?

like image 943
GiDar Avatar asked Sep 07 '15 18:09

GiDar


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 .

What is Localization & Globalization in ASP.NET core?

Globalization adds support for input, display, and output of a defined set of language scripts that relate to specific geographic areas. Localization is the process of adapting a globalized app, which you have already processed for localizability, to a particular culture/locale.

What is localization C#?

Localization is the process of customizing your application for a given culture and locale. Cultures and Locales. The language needs to be associated with the particular region where it is spoken, and this is done by using locale (language + location).

What is globalization and localization in ASP NET Core?

Globalization and localization in ASP.NET Core. Creating a multilingual website with ASP.NET Core will allow your site to reach a wider audience. ASP.NET Core provides services and middleware for localizing into different languages and cultures. Internationalization involves Globalization and Localization.

How to use DataAnnotations and localization in MVC?

Using DataAnnotations and Localization in ASP.NET Core MVC. This article shows how ASP.NET Core localization can be used together with data annotations. The data annotations are used to decorate the data model, and when HTTP POST/PUT (also PATCH) Requests are sent with model errors, the error message is returned localized in the request culture.

How to localize a MVC 5 web site?

Now go to the browser and change the language for Tool -> Internet Options. Click the Add button. Select the language depending on your resource file language and click ok. Run you application and click the submit button. In this article I have explained how to localize easily and properly a MVC 5 web site.

Are non-validation attributes localized in core MVC?

In ASP.NET Core MVC 1.1.0 and higher, non-validation attributes are localized. ASP.NET Core MVC 1.0 does not look up localized strings for non-validation attributes. The following code shows how to use one resource string for validation attributes with multiple classes:


1 Answers

Beta 7 introduced the localization, so it's really brand new. I wrote a short write up of everything that is new on my blog. There are a lot of things new, so if you need the features, I recommend reading it.

You can in fact still use Resx, but you have to understand that the resolution by default is, that the engine tries to find the resx file that matches the view.

For example, if you have a HomeController, and an action called Locpage, you need to have Views.Home.Locpage.cshtml.en-GB.resx to Support en-GB locale. The best part, however, is that you don't really need a resx file anymore :-). You can just implement your own implementation of IStringLocalizer and IStringLocalizerFactory, and it'll work. You can see the code for this on my blog, above.

If you want a working sample, the best place right now is their GitHub, so this right here: https://github.com/aspnet/Mvc/tree/dev/samples/LocalizationSample.Web.

like image 127
Anže Vodovnik Avatar answered Oct 07 '22 11:10

Anže Vodovnik