---
title: "ウォークスルー:ローカリゼーションとコンテンツ翻訳の設定"
slug: "walkthrough--configuring-localization-and-content-translation"
abstract: "レンダリングエンジンのローカリゼーションとコンテンツ翻訳の設定ガイド。"
---
# ウォークスルー:ローカリゼーションとコンテンツ翻訳の設定

> !重要以前にアプリを統合していた場合、それは旧版のASP.NETコアレンダリングSDK(バージョン22以前)を使用しています。このSDKは更新を受け取っていないため、[最新のバージョンへのアップグレード](https://doc.sitecore.com/xmc/en/developers/asp-net/latest/asp-net-core-sdk/upgrade-from-v22.html) をお勧めします。

[SitecoreレンダリングエンジンのSDK](https://doc.sitecore.com/xp/ja/developers/hd/19/sitecore-headless-development/sitecore-asp-net-rendering-sdk.md "Sitecore ASP.NET Rendering SDK")は、ASP.NET Coreと同様にグローバル化とローカリゼーションをサポートしています。

グローバリゼーションとローカリゼーションに関する詳細は、公式のMicrosoft [ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-3.1)ドキュメントをご覧ください。

レンダリングエンジンSDKを用いて構築された.NETコアレンダリングホストアプリケーションでは、グローバル化とローカリゼーションを追加するには最小限の設定が必要です。この設定の大部分はレンダリングホストアプリケーションのStartupクラスで行われます。

Startupクラスに関する詳細は、[ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/startup?view=aspnetcore-3.1)の公式のMicrosoft App Startupドキュメントをご覧ください。

このウォークスルーでは、以下の方法を説明します:

-   [ローカリゼーションの設定](https://doc.sitecore.com/xp/ja/developers/hd/19/sitecore-headless-development/walkthrough--configuring-localization-and-content-translation.html#UUID-347cca47-0a37-ef48-6d2a-8de41259b414_section-idm231932714121579 "Configure localization")
-   [ローカリゼーションミドルウェアの設定](https://doc.sitecore.com/xp/ja/developers/hd/19/sitecore-headless-development/walkthrough--configuring-localization-and-content-translation.html#UUID-347cca47-0a37-ef48-6d2a-8de41259b414_section-idm231932714411484 "Configure the localization middleware")

## ローカリゼーションの設定

まずレンダリングエンジンをローカリゼーションに設定する必要があります:

-   Startup.csクラスに以下のコードを追加します:
    
    public void ConfigureServices(IServiceCollection services)
    {
     services.AddLocalization(options => options.ResourcesPath = "Resources");
    
     services.AddSitecoreRenderingEngine(options =>
     {
     options.AddPartialView("Sample-Layout", "\_SampleLayout")
     .AddDefaultPartialView("\_ComponentNotFound");
     });
    }
    

## ローカリゼーションミドルウェアの設定

リクエスト上の現在の文化はローカリゼーションミドルウェアで設定されています。

ローカリゼーションミドルウェアの設定:

1.  Startup.csクラスのConfigure法では、callapp.UseRequestLocalization(options =>{})を加えます。
    
    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();
    }
    
    > !注UseSitecoreRequestLocalization() メソッドは、sc\_langクエリ文字列とルートデータ(例: en-us)からのカルチャートークンの両方から文化を解決できるようにします。
    > 
    > UseRequestLocalizationメソッドを呼び出しない場合は、WithDefaultRequestOptionsメソッドで指定された言語が代わりに使われます。
    
2.  Startup.csの場合、Configureメソッドのapp.UseEndpoints(endpoints =>{})呼び出しで、エンドポイントの設定やローカライズドルートの追加のために以下を追加してください:
    
    app.UseEndpoints(endpoints =>
     {
     endpoints.AddLocalizedRoute("Localized", "Index", "Sitecore");
     endpoints.MapFallbackToController("Index", "Sitecore");
     });
    
    AddLocalizedRouteメソッドはルート名、デフォルトアクション、コントローラー名の3つのパラメータを受け付けます。以下のパターンでコントローラルートをマッピングします:
    
    /{culture:culture}/{\*\*sitecoreRoute}
    
    カスタムルーティングを希望する場合は、cultureとsitecoreRouteルートの値をRouteValuesのHttpRequestオブジェクトコレクションで見つけることができます。 [「ASP.NET Coreのルーティング](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-3.1#url-matching)」を参照してください。
    

### メソッド概要の設定

以下は、ローカリゼーションミドルウェアを設定した後の完全なConfigureメソッドの例ですStartup.cs :

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");
 });
}

> !注ローカリゼーションが有効なレンダリングホストの動作例は [、開始テンプレート](https://doc.sitecore.com/xp/ja/developers/hd/19/sitecore-headless-development/walkthrough--using-the-getting-started-template.html "Walkthrough: Using the Getting Started template") をご覧ください。