mirror of https://github.com/abpframework/abp.git
5 changed files with 87 additions and 2 deletions
@ -0,0 +1,17 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
|
||||
|
namespace Microsoft.AspNetCore.RequestLocalization |
||||
|
{ |
||||
|
public class AbpRequestLocalizationOptions |
||||
|
{ |
||||
|
public List<Func<IServiceProvider, RequestLocalizationOptions, Task>> RequestLocalizationOptionConfigurators { get; } |
||||
|
|
||||
|
public AbpRequestLocalizationOptions() |
||||
|
{ |
||||
|
RequestLocalizationOptionConfigurators = new List<Func<IServiceProvider, RequestLocalizationOptions, Task>>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
using System.Globalization; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Localization |
||||
|
{ |
||||
|
[Route("api/LocalizationTestController")] |
||||
|
public class LocalizationTestController : AbpController |
||||
|
{ |
||||
|
[HttpGet] |
||||
|
public string Culture() |
||||
|
{ |
||||
|
return CultureInfo.CurrentCulture.Name + ":" + CultureInfo.CurrentUICulture.Name; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
using System.Net; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.AspNetCore.Localization; |
||||
|
using Microsoft.AspNetCore.RequestLocalization; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Microsoft.Extensions.Primitives; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Localization |
||||
|
{ |
||||
|
public class LocalizationTestController_Tests : AspNetCoreMvcTestBase |
||||
|
{ |
||||
|
class TestRequestCultureProvider : RequestCultureProvider, ITransientDependency |
||||
|
{ |
||||
|
public override Task<ProviderCultureResult> DetermineProviderCultureResult(HttpContext httpContext) |
||||
|
{ |
||||
|
return Task.FromResult(new ProviderCultureResult((StringSegment) "tr", (StringSegment) "hu")); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) |
||||
|
{ |
||||
|
services.Configure<AbpRequestLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.RequestLocalizationOptionConfigurators.Add((provider, localizationOptions) => |
||||
|
{ |
||||
|
localizationOptions.RequestCultureProviders.Insert(0, provider.GetRequiredService<TestRequestCultureProvider>()); |
||||
|
return Task.CompletedTask; |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task TestRequestCultureProvider_Test() |
||||
|
{ |
||||
|
var response = await GetResponseAsync("api/LocalizationTestController", HttpStatusCode.OK); |
||||
|
var resultAsString = await response.Content.ReadAsStringAsync(); |
||||
|
resultAsString.ToLower().ShouldBe("tr:hu"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue