Merge the master branch of aspnet/Localization
This commit is contained in:
commit
82184e9710
|
|
@ -3,7 +3,7 @@
|
|||
<PropertyGroup>
|
||||
<Product>Microsoft ASP.NET Core</Product>
|
||||
<Description>Provides a request culture provider which gets culture and ui-culture from request's route data.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;localization</PackageTags>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
Localization
|
||||
============
|
||||
|
||||
Localization abstractions and implementations for ASP.NET Core applications.
|
||||
|
||||
### Localization Samples
|
||||
|
||||
Here are a few samples that demonstrate different localization features including: localized views, localized strings in data annotations, creating custom localization resources ... etc.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.1;netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -23,18 +23,17 @@ namespace LocalizationSample
|
|||
|
||||
public void Configure(IApplicationBuilder app, IStringLocalizer<Startup> SR)
|
||||
{
|
||||
var supportedCultures = new [] { "en-US", "en-AU", "en-GB", "es-ES", "ja-JP", "fr-FR", "zh", "zh-CN" };
|
||||
var supportedCultures = new[] { "en-US", "en-AU", "en-GB", "es-ES", "ja-JP", "fr-FR", "zh", "zh-CN" };
|
||||
app.UseRequestLocalization(options =>
|
||||
options
|
||||
.AddSupportedCultures(supportedCultures)
|
||||
.AddSupportedUICultures(supportedCultures)
|
||||
.SetDefaultCulture(supportedCultures[0])
|
||||
// Optionally create an app-specific provider with just a delegate, e.g. look up user preference from DB.
|
||||
// Inserting it as position 0 ensures it has priority over any of the default providers.
|
||||
//.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context =>
|
||||
//{
|
||||
// Optionally create an app-specific provider with just a delegate, e.g. look up user preference from DB.
|
||||
//.AddRequestCultureProvider(new CustomRequestCultureProvider(async context =>
|
||||
//{
|
||||
|
||||
//}));
|
||||
//}));
|
||||
);
|
||||
|
||||
app.Use(async (context, next) =>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<PropertyGroup>
|
||||
<Product>Microsoft ASP.NET Core</Product>
|
||||
<Description>ASP.NET Core middleware for automatically applying culture information to HTTP requests. Culture information can be specified in the HTTP header, query string, cookie, or custom source.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;localization</PackageTags>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
|
||||
namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for the <see cref="RequestLocalizationOptions"/>.
|
||||
/// </summary>
|
||||
public static class RequestLocalizationOptionsExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a new <see cref="RequestCultureProvider"/> to the <see cref="RequestLocalizationOptions.RequestCultureProviders"/>.
|
||||
/// </summary>
|
||||
/// <param name="requestLocalizationOptions">The cultures to be added.</param>
|
||||
/// <param name="requestCultureProvider">The cultures to be added.</param>
|
||||
/// <returns>The <see cref="RequestLocalizationOptions"/>.</returns>
|
||||
/// <remarks>This method ensures that <paramref name="requestCultureProvider"/> has priority over other <see cref="RequestCultureProvider"/> instances in <see cref="RequestLocalizationOptions.RequestCultureProviders"/>.</remarks>
|
||||
public static RequestLocalizationOptions AddInitialRequestCultureProvider(
|
||||
this RequestLocalizationOptions requestLocalizationOptions,
|
||||
RequestCultureProvider requestCultureProvider)
|
||||
{
|
||||
if (requestLocalizationOptions == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(requestLocalizationOptions));
|
||||
}
|
||||
|
||||
if (requestCultureProvider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(requestCultureProvider));
|
||||
}
|
||||
|
||||
requestLocalizationOptions.RequestCultureProviders.Insert(0, requestCultureProvider);
|
||||
|
||||
return requestLocalizationOptions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Localization
|
||||
{
|
||||
public class RequestLocalizationOptionsExtensionsTest
|
||||
{
|
||||
[Fact]
|
||||
public void AddInitialRequestCultureProvider_ShouldBeInsertedAtFirstPostion()
|
||||
{
|
||||
// Arrange
|
||||
var options = new RequestLocalizationOptions();
|
||||
var provider = new CustomRequestCultureProvider(context => Task.FromResult(new ProviderCultureResult("ar-YE")));
|
||||
|
||||
// Act
|
||||
options.AddInitialRequestCultureProvider(provider);
|
||||
|
||||
// Assert
|
||||
Assert.Same(provider, options.RequestCultureProviders[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in New Issue