Localizing and globalizing with ASP.NET Core
In Chapter 7, Handling Dates, Times, and Internationalization, you learned about working with dates, times, and time zones, and how to globalize and localize a .NET codebase.
In this section, we will look specifically at how to localize a website that uses ASP.NET Core.
As well as localizing string
values into languages like French and Spanish using IStringLocalizer
, you can localize HTML content using IHtmlLocalizer
, but this should be used with care. Usually, HTML markup should be the same for all locales. For views, you can use IViewLocalizer
.
Request localization means that the browser can request what culture it prefers in the following ways:
- Add a query string parameter, for example,
?culture=en-US&ui-culture=en-US
. - Send a cookie with the request, for example,
c=en-US|uic=en-US
. - Set an HTTP header, for example,
Accept-Language: en-US,en;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-GB;q=0.6
.
To enable...