Merge pull request #8584 from umbraco/netcore/feature/request-localization-from-user
Netcore: Added request localization from the current user.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Umbraco.Core.Security;
|
||||
|
||||
namespace Umbraco.Web.Common.Extensions
|
||||
{
|
||||
public class UmbracoBackOfficeIdentityCultureProvider : RequestCultureProvider
|
||||
{
|
||||
public override Task<ProviderCultureResult> DetermineProviderCultureResult(HttpContext httpContext)
|
||||
{
|
||||
var culture = httpContext.User.Identity.GetCulture();
|
||||
|
||||
if (culture is null)
|
||||
{
|
||||
return NullProviderCultureResult;
|
||||
}
|
||||
|
||||
return Task.FromResult(new ProviderCultureResult(culture.Name, culture.Name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@@ -13,7 +15,6 @@ using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Serilog.Extensions.Hosting;
|
||||
using Serilog.Extensions.Logging;
|
||||
using Umbraco.Composing;
|
||||
using Umbraco.Configuration;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
@@ -26,6 +27,7 @@ using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Runtime;
|
||||
using Umbraco.Web.Common.AspNetCore;
|
||||
using Umbraco.Web.Common.Extensions;
|
||||
using Umbraco.Web.Common.Profiler;
|
||||
|
||||
namespace Umbraco.Extensions
|
||||
@@ -154,7 +156,7 @@ namespace Umbraco.Extensions
|
||||
out factory);
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the Umbraco Back Core requirements
|
||||
@@ -182,6 +184,7 @@ namespace Umbraco.Extensions
|
||||
if (container is null) throw new ArgumentNullException(nameof(container));
|
||||
if (entryAssembly is null) throw new ArgumentNullException(nameof(entryAssembly));
|
||||
|
||||
// Add supported databases
|
||||
services.AddUmbracoSqlCeSupport();
|
||||
services.AddUmbracoSqlServerSupport();
|
||||
|
||||
@@ -228,7 +231,7 @@ namespace Umbraco.Extensions
|
||||
factory = coreRuntime.Configure(container);
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
private static ITypeFinder CreateTypeFinder(Core.Logging.ILogger logger, IProfiler profiler, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, ITypeFinderSettings typeFinderSettings)
|
||||
{
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace Umbraco.Extensions
|
||||
{
|
||||
services.ConfigureOptions<UmbracoMvcConfigureOptions>();
|
||||
services.TryAddEnumerable(ServiceDescriptor.Transient<IApplicationModelProvider, UmbracoApiBehaviorApplicationModelProvider>());
|
||||
services.TryAddEnumerable(ServiceDescriptor.Transient<IApplicationModelProvider, BackOfficeApplicationModelProvider>());
|
||||
|
||||
// TODO: We need to avoid this, surely there's a way? See ContainerTests.BuildServiceProvider_Before_Host_Is_Configured
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
Reference in New Issue
Block a user