---
title: "Walkthrough: Configuring localization and content translation"
slug: "walkthrough--configuring-localization-and-content-translation"
abstract: "Guide to configuring localization and content translation for a rendering engine."
---
# Walkthrough: Configuring localization and content translation

> [!important]
> If you integrated your app before , 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](https://doc.sitecore.com/xmc/en/developers/asp-net/latest/asp-net-core-sdk/upgrade-from-v22.html) .

The [Sitecore Rendering Engine SDK](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-headless-development/sitecore-asp-net-rendering-sdk--legacy-.html "Sitecore ASP.NET Rendering SDK (legacy)") 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](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-3.1) 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](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/startup?view=aspnetcore-3.1) documentation.

This walkthrough describes how to:

- [Configure localization](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-headless-development/walkthrough--configuring-localization-and-content-translation.html#UUID-ee30f347-10eb-2754-c783-eb07ef0bd0d9_section-idm231932714121579 "Configure localization")
- [Configure the localization middleware](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-headless-development/walkthrough--configuring-localization-and-content-translation.html#UUID-ee30f347-10eb-2754-c783-eb07ef0bd0d9_section-idm231932714411484 "Configure the localization middleware")

## Configure localization

You must first configure the Rendering Engine to use localization:

- Add the following code to the `Startup.cs` class:

    ```csharp
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddLocalization(options => options.ResourcesPath = "Resources");

        services.AddSitecoreRenderingEngine(options =>
        {
            options.AddPartialView("Sample-Layout", "_SampleLayout")
                   .AddDefaultPartialView("_ComponentNotFound");
        });
    }
    ```

## Configure the localization middleware

The current culture on a request is set in the localization middleware.

To configure the localization middleware:

1. In the `Startup.cs` class, in the `Configure` method, add `callapp.UseRequestLocalization(options =>{})`.

    ```csharp
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseRouting();
        app.UseStaticFiles();
        app.UseRequestLocalization(options =>
        {
            var supportedCultures = new List<CultureInfo> { new CultureInfo("en"), new CultureInfo("da"), new CultureInfo("da-DK") };
            options.DefaultRequestCulture = new RequestCulture(culture: "da", uiCulture: "da");
            options.SupportedCultures = supportedCultures;
            options.SupportedUICultures = supportedCultures;
            options.UseSitecoreRequestLocalization();
        });
        app.UseSitecoreRenderingEngine();
    }
    ```

    > [!note]
    > The `UseSitecoreRequestLocalization()` method allows culture to resolve from both the `sc_lang` query string and the culture token from route data (for example, `en-us`).
    >
    > If you do not invoke the `UseRequestLocalization` method, the language specified in `WithDefaultRequestOptions` method is used instead.

2. In `Startup.cs`, in the `app.UseEndpoints(endpoints =>{})` call in the `Configure` method, add the following to configure endpoints and add localized routes:

    ```csharp
    app.UseEndpoints(endpoints =>
        {
            endpoints.AddLocalizedRoute("Localized", "Index", "Sitecore");
            endpoints.MapFallbackToController("Index", "Sitecore");
        });
    ```

    The `AddLocalizedRoute` method accepts three parameters: the route name, default action, and controller name. It maps the controller route using the following pattern:

    ```text
    /{culture:culture}/{**sitecoreRoute}
    ```

    If you want custom routing, you can find the `culture` and `sitecoreRoute` route values in the `RouteValues` collection of `HttpRequest` objects. See [Routing in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-3.1#url-matching).

### Configure method overview

The following is an example of the full `Configure` method in `Startup.cs` once you have configured the localization middleware:

```csharp
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseRouting();
    app.UseStaticFiles();
    app.UseRequestLocalization(options =>
    {
        var supportedCultures = new List<CultureInfo> { new CultureInfo("en"), new CultureInfo("da"), new CultureInfo("da-DK") };
        options.DefaultRequestCulture = new RequestCulture(culture: "da", uiCulture: "da");
        options.SupportedCultures = supportedCultures;
        options.SupportedUICultures = supportedCultures;
        options.UseSitecoreRequestLocalization();
    });
    app.UseSitecoreRenderingEngine();

    app.UseEndpoints(endpoints =>
    {
        endpoints.AddLocalizedRoute("Localized", "Index", "Sitecore");
        endpoints.MapFallbackToController("Index", "Sitecore");
    });
}

```

> [!note]
> See the [getting started template](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-headless-development/walkthrough--using-the-getting-started-template.html "Walkthrough: Using the Getting Started template") for a working example of a rendering host with localization enabled.