Localization of Validation and Metadata Strings
Explore how to effectively localize validation and metadata strings in ASP.NET Core MVC. Learn to organize resource files by type namespaces, use IStringLocalizer and IHtmlLocalizer interfaces, and enable automatic data annotations localization for maintainable and scalable multilingual web apps.
IViewLocalizer and culture-specific views do not cover all needs, as we have:
-
General purpose strings that are not associated with specific views but can be used in several views. Since duplications kill modularity and modifiability, we must avoid duplicating these strings in several resource files and place them in unique places. We associate them with types instead of views. These types should be associated with the role of the strings to be translated. For instance, we may associate all strings needed by a business service that is injected into several controllers to the business service type. Global strings such as the application name can be associated with the
Startupclass that represents the whole application. We may also create fake empty classes that represent string roles, just to organize resources around them. -
Messages coming from data annotations. They are automatically added to the views so ...