# Localization

Localization makes UI components more friendly by talking with users in language they speak.

# Configuration

  1. Ext.NET localization files are embedded resources, ensure hosting of embedded resources is enabled in Startup.cs. Ext.NET localization middleware must be enabled after app.UseExtNetResources() invocation (not necessarily as the next statement, so feel free to select the best place for it in the request pipeline).
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    // ...

    // 1. Enable hosting of Ext.NET resources
    app.UseExtNetResources();

    // 2. Enable Ext.NET localization
    app.UseExtNetLocalization();

    // ...
}
  1. Optional The UseExtNetLocalization method accepts a setup action for RequestLocalizationOptions mimicking the signature of the standard UseRequestLocalization method. Internally Ext.NET will resolve supported cultures and initialize the corresponding fields in a RequestLocalizationOptions instance. Feel free to customize it further, e.g.:

Read more about ASP.NET localization here.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    // ...

    // 1. Enable hosting of Ext.NET resources
    app.UseExtNetResources();

    // 2. Enable Ext.NET localization
    app.UseExtNetLocalization(config =>
    {
        // Override the default logic to support
        // a "lang" query string parameter only.
        config.RequestCultureProviders = new[]
        {
            new QueryStringRequestCultureProvider
            {
                UIQueryStringKey = "lang"
            }
        };
    });

    // ...
}

With the configuration above, the lang query string parameter can be used to control UI Culture:

# Per-page locale configuration

Ext.NET uses the CultureInfo.CurrentUICulture for configuring UI components locale. However, UI Culture can be overridden using the ExtResourceManager.Locale property.

# Configuration using Tag Helper

# Index.cshtml

<head>
    <ext-resourceManager locale="de" />
</head>

# Configuration using a Resource Manager model

As any ohter Ext.NET model, Resource Manager instance can be bound to a <ext-resourceManager /> tag. This way configuration can be implemented within the view model.

# Index.cshtml

<head>
    <ext-resourceManager model="Model.ResourceManager" />
</head>

# Index.cshtml.cs

using Ext.Net.Core;

using Microsoft.AspNetCore.Mvc.RazorPages;

namespace WebApplication1.Pages
{
    public class IndexModel : PageModel
    {
        public ExtResourceManager ResourceManager { get; set; }

        public IndexModel()
        {
            ResourceManager = new ExtResourceManager
            {
                Locale = "de"
            };
        }
    }
}

Any of configurations above will force Ext.NET to use a custom locale configured for that page. Values coming from Culture Providers configured in Localization middleware are ignored in this case (see below, es query string locale is not applied - de page locale is used instead).