-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7011 from abpframework/maliming/AbpRequestLocaliz…
…ationOptions Introduce AbpRequestLocalizationOptions
- Loading branch information
Showing
5 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
....Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestLocalizationOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...p.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/LocalizationTestController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...etCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/LocalizationTestController_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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 Xunit; | ||
|
||
namespace Volo.Abp.AspNetCore.Mvc.Localization | ||
{ | ||
public class LocalizationTestController_Tests : AspNetCoreMvcTestBase | ||
{ | ||
class TestRequestCultureProvider : RequestCultureProvider | ||
{ | ||
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((serviceProvider, localizationOptions) => | ||
{ | ||
localizationOptions.RequestCultureProviders.Insert(0, new 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"); | ||
} | ||
} | ||
} |