Getting RouteDataRequestCultureProvider from Microsoft.AspNetCore.Localization.Routing package
This commit is contained in:
parent
4e6fd823cf
commit
de7cea4000
|
|
@ -5,6 +5,7 @@ using System.Globalization;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Localization;
|
using Microsoft.AspNetCore.Localization;
|
||||||
using Microsoft.AspNetCore.Mvc.Localization;
|
using Microsoft.AspNetCore.Mvc.Localization;
|
||||||
|
using Microsoft.AspNetCore.Localization.Routing;
|
||||||
|
|
||||||
namespace FiltersWebSite
|
namespace FiltersWebSite
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,72 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Routing;
|
|
||||||
using Microsoft.AspNetCore.Localization;
|
|
||||||
|
|
||||||
namespace FiltersWebSite
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Determines the culture information for a request via values in the route data.
|
|
||||||
/// </summary>
|
|
||||||
public class RouteDataRequestCultureProvider : RequestCultureProvider
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The key that contains the culture name.
|
|
||||||
/// Defaults to "culture".
|
|
||||||
/// </summary>
|
|
||||||
public string RouteDataStringKey { get; set; } = "culture";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The key that contains the UI culture name. If not specified or no value is found,
|
|
||||||
/// <see cref="RouteDataStringKey"/> will be used.
|
|
||||||
/// Defaults to "ui-culture".
|
|
||||||
/// </summary>
|
|
||||||
public string UIRouteDataStringKey { get; set; } = "ui-culture";
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Task<ProviderCultureResult> DetermineProviderCultureResult(HttpContext httpContext)
|
|
||||||
{
|
|
||||||
if (httpContext == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(httpContext));
|
|
||||||
}
|
|
||||||
|
|
||||||
string culture = null;
|
|
||||||
string uiCulture = null;
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(RouteDataStringKey))
|
|
||||||
{
|
|
||||||
culture = httpContext.GetRouteValue(RouteDataStringKey) as string;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(UIRouteDataStringKey))
|
|
||||||
{
|
|
||||||
uiCulture = httpContext.GetRouteValue(UIRouteDataStringKey) as string;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (culture == null && uiCulture == null)
|
|
||||||
{
|
|
||||||
// No values specified for either so no match
|
|
||||||
return Task.FromResult((ProviderCultureResult)null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (culture != null && uiCulture == null)
|
|
||||||
{
|
|
||||||
// Value for culture but not for UI culture so default to culture value for both
|
|
||||||
uiCulture = culture;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (culture == null && uiCulture != null)
|
|
||||||
{
|
|
||||||
// Value for UI culture but not for culture so default to UI culture value for both
|
|
||||||
culture = uiCulture;
|
|
||||||
}
|
|
||||||
|
|
||||||
var providerResultCulture = new ProviderCultureResult(culture, uiCulture);
|
|
||||||
|
|
||||||
return Task.FromResult(providerResultCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNetCore.Authentication": "1.1.0-*",
|
"Microsoft.AspNetCore.Authentication": "1.1.0-*",
|
||||||
|
"Microsoft.AspNetCore.Localization.Routing": "1.1.0-*",
|
||||||
"Microsoft.AspNetCore.Mvc": "1.1.0-*",
|
"Microsoft.AspNetCore.Mvc": "1.1.0-*",
|
||||||
"Microsoft.AspNetCore.Mvc.Formatters.Xml": "1.1.0-*",
|
"Microsoft.AspNetCore.Mvc.Formatters.Xml": "1.1.0-*",
|
||||||
"Microsoft.AspNetCore.Mvc.TestConfiguration": "1.0.0",
|
"Microsoft.AspNetCore.Mvc.TestConfiguration": "1.0.0",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue