Globalization and localization
Internationalization involves Globalization and Localization.
Globalization is the process of designing apps that support different cultures. Globalization adds support for input, display, and output of a defined set of language scripts that relate to specific geographic areas.
Localization is the process of adapting a globalized app, which you have already processed for localizability, to a particular culture/locale.
Use localization
IStringLocalizer
and IStringLocalizer<T>
were architected to improve productivity when developing localized apps. IStringLocalizer
uses the ResourceManager
and ResourceReader
to provide culture-specific resources at run time.
A French resource file could contain the following:
Key
Value
<i>Hello</i> <b>{0}!</b>
<i>Bonjour</i> <b>{0} !</b>
Note: You generally want to only localize text and not HTML.
Configure localization
Localization is configured in the Startup.ConfigureServices
method:
AddLocalization
Adds the localization services to the services container. The code above also sets the resources path to "Resources".AddViewLocalization
Adds support for localized view files. In this sample view localization is based on the view file suffix. For example "fr" in the Index.fr.cshtml file.AddDataAnnotationsLocalization
Adds support for localizedDataAnnotations
validation messages throughIStringLocalizer
abstractions.
Localization middleware
The current culture on a request is set in the localization middleware. The localization middleware is enabled in the Startup.Configure
method.
Last updated