---
title: "How to Use Localization in an ASP.NET Core Web API"
published_at: "2020-04-07T11:18:52+00:00"
modified_at: "2026-01-12T12:11:21+00:00"
url: "https://www.syncfusion.com/blogs/post/localization-in-asp-net-core"
excerpt: "TL;DR: Enable Your ASP.NET Core Web API for Global Expansion! Explore efficient localization techniques using resource files. Learn how to deliver a seamless user experience across languages, reaching new markets and maximizing your impact. To serve people from any culture..."
taxonomy_category:
  - "ASP.NET Core"
taxonomy_post_tag:
  - "ASP.NET Core"
  - "Localization"
  - "Web API"
  - "webdev"
---

# How to Use Localization in an ASP.NET Core Web API

[Ragunaathan Pandurangan](https://www.syncfusion.com/blogs/author/ragunaathan-pandurangan)

![How to use Localization in ASP.Net Core Web API](https://www.syncfusion.com/blogs/wp-content/uploads/2020/04/How-to-use-Localization-in-ASP.Net-Core-Web-API-1.jpg)


**TL;DR:** Enable Your ASP.NET Core Web API for Global Expansion! Explore efficient localization techniques using resource files. Learn how to deliver a seamless user experience across languages, reaching new markets and maximizing your impact.

To serve people from any culture who use any language, most web applications nowadays have localization support.

[Localization](https://en.wikipedia.org/wiki/Localization)
 is a process that translates content for a specific culture. It can be used to serve a multilingual, worldwide audience and achieve better market reach.

In this blog, we are going to learn about how to use localization in an [ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/)
 web API with resource (.resx) files.

## Prerequisites

The following are the prerequisites to integrate localization in an ASP.NET Core web API:

- [Visual Studio 2019 (v16.4)](https://visualstudio.microsoft.com/vs/)
- [NET Core 3.1](https://dotnet.microsoft.com/download/dotnet-core/3.1)

## Create an ASP.NET Core REST API application

Follow these steps to create an ASP.NET Core REST API application in Visual Studio 2019:

**Step 1:** In Visual Studio 2019 (v16.4 or higher), go to ** File**>** New**, and then select ** Project**.

**Step 2:** Choose ** Create a new project**.

**Step 3:** Select the ** ASP.NET Core Web Application** template.

**Step 4:** Enter a ** Project name**, and then click ** Create**. The project template dialog will be displayed.

**Step 5:** Select the **.NET Core, ASP.NET Core 3.1**, ** API** template (highlighted in the following screenshot).

![Select .NET Core, ASP.NET Core 3.1, API Template](https://www.syncfusion.com/blogs/wp-content/uploads/2020/04/Select-.NET-Core-ASP.NET-Core-3.1-API-Template.png)

Select .NET Core, ASP.NET Core 3.1, API Template

## Configuring start-up

**Step 1:** Register the necessary services for the localization process in the ** ConfigureServices** method in the ** Startup.cs** class: ** AddLocalization()** and ** Configure<RequestLocalizationOptions>()**.

![Add Localization Services](https://www.syncfusion.com/blogs/wp-content/uploads/2020/04/Add-Localization-Services.png)

Add Localization Services

**Step 2:** Add the request localization middleware in the ** Configure** method from the ** Startup.cs**class.

![Configure Request Localization Middleware](https://www.syncfusion.com/blogs/wp-content/uploads/2020/04/Configure-Request-Localization-Middleware.jpg)

Configure-Request Localization Middleware

## Strategy for resource files

Resource files contain localizable strings based on the culture and the controller. We can maintain the resource files in two ways:

- Single culture resource file per controller.
- Single culture resource file for all controllers.

## Single culture resource file per controller

In this method, you need to maintain a separate resource file for each culture and each controller in any file structure (i.e. dot or path) as mentioned in [this documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-3.1#resource-file-naming)
.

**Example:**

If you have two controllers and support for two cultures, then you need to maintain the resource files in the structure shown in the following screenshot.

Here, we have support for the US English and French languages.

![Resource File Structure](https://www.syncfusion.com/blogs/wp-content/uploads/2020/04/Resource-File-Structure.jpg)

Resource File Structure

## Single culture resource file for all controllers

In this method, you should maintain a single resource file based on culture for all the controllers.

To do this, you need to create an empty class with the same name as the resource file. The namespace of this empty class will be used to find the resource manager and resolve **IStringLocalizer<T>** abstractions.

**Example:**

Despite of the number of controllers, you should only maintain one resource file for every culture supported.

Refer to the following screenshot to see this approach in practice.

![Resource File Structure](https://www.syncfusion.com/blogs/wp-content/uploads/2020/04/Resource-File-Structure1.jpg)

Resource File Structure

## How to use localized values in controllers

ASP.NET Core provides built-in support for **IStringLocalizer** and ** IStringLocalizer<T>**abstractions. These abstractions are used to get the values based on the name of the string resource passed from the respective culture resource file (e.g., HomeController.en-US.resx).

To use localized values in the controllers, you need to inject the **IStringLocalizer<T>** abstraction based on the resource file structure mapped as shown in the following table.

| Controller Name | Dependency Injection of IStringLocalizer<T> | Resource File Structure |
| --- | --- | --- |
| HomeController | IStringLocalizer<HomeController> | Resources/Controllers/HomeController.en-US.resx |
| AboutController | IStringLocalizer<AboutController> | Resources/Controllers/AboutController.en-US.resx |
| For all controllers | IStringLocalizer<Resource> | Resource.en-US.resx |

Based on injecting the **IStringLocalizer<T>** abstraction, the string localizer will map the resource file through the value passed to the shared resource (**T**). This string localizer will then return the mapped value from the resource file based on the name of the string resource you have passed.

![IStringLocalizer Abstraction](https://www.syncfusion.com/blogs/wp-content/uploads/2020/04/IStringLocalizer-Abstraction.jpg)

IStringLocalizer Abstraction

## Resources

You can find a copy of these samples in the following GitHub locations:

- [LocalizationSampleWebAPI](https://github.com/RaguMP/Samples/tree/master/LocalizationSampleWebAPI)
- [LocalizationSampleSingleResxFile](https://github.com/RaguMP/Samples/tree/master/LocalizationSampleSingleResxFile)

## Conclusion

In this blog, we learned about implementing localization in an ASP .NET Core web API application. This feature helps to serve multilingual people from diverse cultures.

Syncfusion provides over 70 high-performance, lightweight, modular, and responsive [ASP.NET Core UI controls](https://www.syncfusion.com/aspnet-core-ui-controls)
 such as [DataGrid](https://www.syncfusion.com/aspnet-core-ui-controls/grid)
, [Charts](https://www.syncfusion.com/aspnet-core-ui-controls/charts)
, and [Scheduler](https://www.syncfusion.com/aspnet-core-ui-controls/scheduler)
, and all of them have built-in support for localization. You can use them to improve your application development.

Please share your feedback on this blog in the comments section. You can also contact us through our [support forum](https://www.syncfusion.com/forums)
, [support portal](https://www.syncfusion.com/account/login)
, or [feedback portal](https://www.syncfusion.com/feedback)
. We are waiting to hear from you!

## Related blogs

- [Simple Steps to View a PowerPoint Presentation in an ASP.NET Core Application](https://www.syncfusion.com/blogs/post/view-powerpoint-asp-dotnet-core.aspx)
- [Easily Group Data into Ranges in Web Applications Using Pivot Table](https://www.syncfusion.com/blogs/post/easily-group-data-into-ranges-in-web-applications-using-pivot-table.aspx)
- [Handling CSV Files in ASP.NET Core Web APIs](https://www.syncfusion.com/blogs/post/handling-csv-files-in-asp-net-core-web-apis.aspx)
- [Simple Steps to Integrate a Blazor WebAssembly Project with an Existing ASP.NET Core Application](https://www.syncfusion.com/blogs/post/integrate-blazor-webassembly-in-asp-net-core-application.aspx)
