2021-01-08 11:29:07 +11:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Localization;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
2021-01-08 11:29:07 +11:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Web.Common.Localization
|
2021-01-08 11:29:07 +11:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Custom Umbraco options configuration for <see cref="RequestLocalizationOptions"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class UmbracoRequestLocalizationOptions : IConfigureOptions<RequestLocalizationOptions>
|
|
|
|
|
{
|
2021-09-27 09:58:44 +02:00
|
|
|
private GlobalSettings _globalSettings;
|
2021-01-08 11:29:07 +11:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="UmbracoRequestLocalizationOptions"/> class.
|
|
|
|
|
/// </summary>
|
2021-10-04 09:18:41 +02:00
|
|
|
public UmbracoRequestLocalizationOptions(IOptionsSnapshot<GlobalSettings> globalSettings)
|
2021-09-27 09:58:44 +02:00
|
|
|
{
|
2021-10-04 09:18:41 +02:00
|
|
|
_globalSettings = globalSettings.Value;
|
2021-09-27 09:58:44 +02:00
|
|
|
}
|
2021-01-08 11:29:07 +11:00
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public void Configure(RequestLocalizationOptions options)
|
|
|
|
|
{
|
|
|
|
|
// set the default culture to what is in config
|
2021-09-27 09:58:44 +02:00
|
|
|
options.DefaultRequestCulture = new RequestCulture(_globalSettings.DefaultUILanguage);
|
2021-01-08 11:29:07 +11:00
|
|
|
|
|
|
|
|
// add a custom provider
|
|
|
|
|
if (options.RequestCultureProviders == null)
|
|
|
|
|
{
|
|
|
|
|
options.RequestCultureProviders = new List<IRequestCultureProvider>();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 13:39:09 +11:00
|
|
|
options.RequestCultureProviders.Insert(0, new UmbracoBackOfficeIdentityCultureProvider(options));
|
|
|
|
|
options.RequestCultureProviders.Insert(1, new UmbracoPublishedContentCultureProvider(options));
|
2021-01-08 11:29:07 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|