Globalization and localization - Provide resources
In this article
SupportedCultures
and SupportedUICultures
Resource files
- In Solution Explorer, right click on the folder that will contain the resource file, and then select Add > New Item.
- In the Search installed templates box, enter "resource" and name the file.
- Enter the key value (native string) in the Name column and the translated string in the Value column.
Visual Studio shows the Welcome.es.resx file.
Resource file naming
Resource name | Dot or path naming |
---|---|
Resources/Controllers.HomeController.fr.resx | Dot |
Resources/Controllers/HomeController.fr.resx | Path |
-
Resources/Views/Home/About.fr.resx
-
Resources/Views.Home.About.fr.resx
RootNamespaceAttribute
Warning This can occur when a project's name is not a valid .NET identifier. For instance
my-project-name.csproj
will use the root namespacemy_project_name
and the assembly namemy-project-name
leading to this error.
-
Localization does not work by default.
-
Localization fails due to the way resources are searched for within the assembly.
RootNamespace
is a build-time value which is not available to the executing process.
using System.Reflection;
using Microsoft.Extensions.Localization;
[assembly: ResourceLocation("Resource Folder Name")]
[assembly: RootNamespace("App Root Namespace")]
Culture fallback behavior
-
Welcome.fr-CA.resx
-
Welcome.fr.resx
-
Welcome.resx (if the
NeutralResourcesLanguage
is "fr-CA")
Generate resource files with Visual Studio
Add other cultures
Next steps
-
Make the app's content localizable.
-
Implement a strategy to select the language/culture for each request
Additional resources
-
Url culture provider using middleware as filters in ASP.NET Core
-
Applying the RouteDataRequest CultureProvider globally with middleware as filters
-
Globalization and localization in ASP.NET Core
-
Make an ASP.NET Core app's content localizable
-
Strategies for selecting language and culture in a localized ASP.NET Core app
-
Troubleshoot ASP.NET Core localization
-
Globalizing and localizing .NET applications
-
Localization.StarterWeb project used in the article.
-
Resources in .resx Files
-
Microsoft Multilingual App Toolkit
-
Localization & Generics
Ref: Provide localized resources for languages and cultures in an ASP.NET Core app