![]() ![]() Step 4: Enter a Project name, and then click Create. Step 3: Select the ASP.NET Core Web Application template. Step 1: In Visual Studio 2019 (v16.4 or higher), go to File > New, and then select Project. The following are the prerequisites to integrate localization in an ASP.NET Core web API:Ĭreate an ASP.NET Core REST API applicationįollow these steps to create an ASP.NET Core REST API application in Visual Studio 2019: In this blog, we are going to learn about how to use localization in an ASP.NET Core web API with resource (.resx) files. It can be used to serve a multilingual, worldwide audience and achieve better market reach. Localization is a process that translates content for a specific culture. To serve people from any culture who use any language, most web applications nowadays have localization support. BoldSign – Electronic Signature Software.Our solution is a good example of how flexible ASP.NET Core is on supporting both small and big scenarios of localization. And as it turned out, we also got away with a simple language route constraint. We wrote a custom string localizer class to handle mapping between “et” and “ee,” and we wrote just a few lines of code for it. Also, we were able to keep things easy and compact. It was easy to create language based URLs, and also to handle the special case where local people are used with “ee” as the language code instead of the official code “et.” We were able to achieve decent language support for applications where new languages are not added often. ![]() ![]() Link text is read from the resource string called CustomLocalizer => m.Categor圜ontent, UpĪSP.NET Core comes with new localization support and it is different from the one used in previous ASP.NET applications. It’s a simple view that outputs a list of articles and below the articles, there is a link to all news lists. Now let’s take a look at view that uses custom localizer. Base class StringLocalizer gets Strings as type and this is the name of resource files. This way we have one localizer class to injeect to views that need localization. Our custom localizer is actually a wrapper that translates “ee” and empty language to “et”. ![]() Provider.Options = opts opts.RequestCultureProviders = new Opts.SupportedUICultures = supportedCultures var provider = new RouteDataRequestCultureProvider() Opts.SupportedCultures = supportedCultures } opts.DefaultRequestCulture = new RequestCulture("et") Public void ConfigureServices(IServiceCollection services) Let’s take the ConfigureServices() method first. We need some modifications to our startup class. Localization is different compared to previous versions of ASP.NET. NB! To find out more about localization and globalization in ASP.NET Core please read the official documentation about it at Setting Up Localization The application has a small amount of translations that are held in resource files (one per language).Īs “ee” is not supported culture and “et” is not very familiar to regular users here, so I needed a way how to hide mapping from “ee” to “et” that way I don’t have to inject this logic to views where translations are needed.Although et-ee is the official notation for localization here, people are used to ee because it is our country domain.Deciding to use a new language means changes in the organization, and it will probably be a high-level decision.We have a limited number of supported languages and the number of languages doesn’t change often.This blog post is a short overview of simple localization that uses some interesting tweaks and framework level dependency injection. So, I decided to share my knowledge and experience with my readers. I had to work with one specific prototyping scenario at work and as I was able to solve some problems that other people may face. ASP.NET Core comes with new support for localization and globalization. ![]()
0 Comments
Leave a Reply. |