Localization of Validation and Metadata Strings
In this lesson, we will learn how to localize general-purpose strings that are not associated with specific views, and strings coming from data annotations, such as metadata and validation error messages.
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
Startup
class that represents the whole application. We may also create fake empty classes that represent string roles, just to organize resources around them. ...