Walkthrough: Configuring localization and content translation
If you integrated your ASP.NET Core app before September 2024, it's using the legacy ASP.NET Core Rendering SDK, version 22 or earlier. This SDK is no longer receiving updates, so we recommend that you upgrade to the latest version of the new ASP.NET Core SDK.
The Sitecore Rendering Engine SDK offers support for globalization and localization, the same as in ASP.NET Core.
For further information about globalization and localization, see the official Microsoft ASP.NET Core documentation.
Minimal configuration is required to add globalization and localization in a .NET Core rendering host application built using the Rendering Engine SDK. Most of this configuration is done in the Startup class of the rendering host application.
For further information about the Startup class, see the official Microsoft App startup in ASP.NET Core documentation.
This walkthrough describes how to:
Configure localization
You must first configure the Rendering Engine to use localization:
-
Add the following code to the
Startup.csclass:
Configure the localization middleware
The current culture on a request is set in the localization middleware.
To configure the localization middleware:
-
In the
Startup.csclass, in theConfiguremethod, addcallapp.UseRequestLocalization(options =>{}).NoteThe
UseSitecoreRequestLocalization()method allows culture to resolve from both thesc_langquery string and the culture token from route data (for example,en-us).If you do not invoke the
UseRequestLocalizationmethod, the language specified inWithDefaultRequestOptionsmethod is used instead. -
In
Startup.cs, in theapp.UseEndpoints(endpoints =>{})call in theConfiguremethod, add the following to configure endpoints and add localized routes:The
AddLocalizedRoutemethod accepts three parameters: the route name, default action, and controller name. It maps the controller route using the following pattern:If you want custom routing, you can find the
cultureandsitecoreRouteroute values in theRouteValuescollection ofHttpRequestobjects. See Routing in ASP.NET Core.
Configure method overview
The following is an example of the full Configure method in Startup.cs once you have configured the localization middleware:
See the getting started template for a working example of a rendering host with localization enabled.