Skip to content

Steps to localize your ASP.NET Core app

Jon P Smith edited this page Jan 7, 2023 · 8 revisions

I didn't find it obvious how to set up .NET localization in ASP.NET Core, so here is a quick list of what you have to set up to help you. The information is already out there, so this is a list of links to Microsoft documentation.

  1. Configure localization which sets up the localization services and the name of the folder that holds the resource files (see step 3 later).
  2. Configure middleware which sets up what cultures you want to support, and ways to get the user's culture.
  3. Create a new class, or use an existing class (e.g. HomeController) to define part of the resource files’ name - I refer to this class as TResource. These TResource classes must be in the ASP.NET Core project.
  4. Add the resource files you need where each resource file that has a filename of {typeof(TResource).{culture name of entries}.resx

I found the Microsoft document didn't have nice step-by-step section on how to setup localization in an ASP.NET Core app, here are some other articles that you might find useful:

NOTE: If you are using the DefaultLocalizer and SimpleLocalizer for all the localization, then you won't need a resource file for the defaultCulture messages, as the strings / FormattableStrings used in these services already have the correct message.

If you want examples of adding localization to an ASP.NET Core app, then have a look at:

Clone this wiki locally