diff --git a/src/Middleware/Localization.Routing/src/Microsoft.AspNetCore.Localization.Routing.csproj b/src/Middleware/Localization.Routing/src/Microsoft.AspNetCore.Localization.Routing.csproj index e946bf8a00..18d5d0788e 100644 --- a/src/Middleware/Localization.Routing/src/Microsoft.AspNetCore.Localization.Routing.csproj +++ b/src/Middleware/Localization.Routing/src/Microsoft.AspNetCore.Localization.Routing.csproj @@ -3,7 +3,7 @@ Microsoft ASP.NET Core Provides a request culture provider which gets culture and ui-culture from request's route data. - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;localization diff --git a/src/Middleware/Localization.Routing/test/Microsoft.AspNetCore.Localization.Routing.Tests.csproj b/src/Middleware/Localization.Routing/test/Microsoft.AspNetCore.Localization.Routing.Tests.csproj index aa56ca5132..90885d402f 100644 --- a/src/Middleware/Localization.Routing/test/Microsoft.AspNetCore.Localization.Routing.Tests.csproj +++ b/src/Middleware/Localization.Routing/test/Microsoft.AspNetCore.Localization.Routing.Tests.csproj @@ -1,7 +1,7 @@  - $(StandardTestTfms) + netcoreapp3.0 diff --git a/src/Middleware/Localization/README.md b/src/Middleware/Localization/README.md index 85f2c83f8b..d5d82d9a30 100644 --- a/src/Middleware/Localization/README.md +++ b/src/Middleware/Localization/README.md @@ -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. diff --git a/src/Middleware/Localization/sample/LocalizationSample.csproj b/src/Middleware/Localization/sample/LocalizationSample.csproj index 77b1172173..6fb61d7925 100644 --- a/src/Middleware/Localization/sample/LocalizationSample.csproj +++ b/src/Middleware/Localization/sample/LocalizationSample.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1;netcoreapp2.0;net461 + netcoreapp3.0 diff --git a/src/Middleware/Localization/sample/Startup.cs b/src/Middleware/Localization/sample/Startup.cs index 8f1bb0d0e6..7b6dd5c4ec 100644 --- a/src/Middleware/Localization/sample/Startup.cs +++ b/src/Middleware/Localization/sample/Startup.cs @@ -23,18 +23,17 @@ namespace LocalizationSample public void Configure(IApplicationBuilder app, IStringLocalizer 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) => diff --git a/src/Middleware/Localization/src/Microsoft.AspNetCore.Localization.csproj b/src/Middleware/Localization/src/Microsoft.AspNetCore.Localization.csproj index 16c71c9157..00f43deee7 100644 --- a/src/Middleware/Localization/src/Microsoft.AspNetCore.Localization.csproj +++ b/src/Middleware/Localization/src/Microsoft.AspNetCore.Localization.csproj @@ -3,7 +3,7 @@ Microsoft ASP.NET Core 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. - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;localization diff --git a/src/Middleware/Localization/src/RequestLocalizationOptionsExtensions.cs b/src/Middleware/Localization/src/RequestLocalizationOptionsExtensions.cs new file mode 100644 index 0000000000..d0bf911c74 --- /dev/null +++ b/src/Middleware/Localization/src/RequestLocalizationOptionsExtensions.cs @@ -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 +{ + /// + /// Extension methods for the . + /// + public static class RequestLocalizationOptionsExtensions + { + /// + /// Adds a new to the . + /// + /// The cultures to be added. + /// The cultures to be added. + /// The . + /// This method ensures that has priority over other instances in . + 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; + } + } +} diff --git a/src/Middleware/Localization/test/FunctionalTests/Microsoft.AspNetCore.Localization.FunctionalTests.csproj b/src/Middleware/Localization/test/FunctionalTests/Microsoft.AspNetCore.Localization.FunctionalTests.csproj index d3d14f4474..46b23f256c 100644 --- a/src/Middleware/Localization/test/FunctionalTests/Microsoft.AspNetCore.Localization.FunctionalTests.csproj +++ b/src/Middleware/Localization/test/FunctionalTests/Microsoft.AspNetCore.Localization.FunctionalTests.csproj @@ -1,7 +1,7 @@  - $(StandardTestTfms) + netcoreapp3.0 diff --git a/src/Middleware/Localization/test/UnitTests/Microsoft.AspNetCore.Localization.Tests.csproj b/src/Middleware/Localization/test/UnitTests/Microsoft.AspNetCore.Localization.Tests.csproj index 8a0fb85de7..0ad51bdc59 100644 --- a/src/Middleware/Localization/test/UnitTests/Microsoft.AspNetCore.Localization.Tests.csproj +++ b/src/Middleware/Localization/test/UnitTests/Microsoft.AspNetCore.Localization.Tests.csproj @@ -1,7 +1,7 @@  - $(StandardTestTfms) + netcoreapp3.0 diff --git a/src/Middleware/Localization/test/UnitTests/RequestLocalizationOptionsExtensionsTest.cs b/src/Middleware/Localization/test/UnitTests/RequestLocalizationOptionsExtensionsTest.cs new file mode 100644 index 0000000000..1910fa95b6 --- /dev/null +++ b/src/Middleware/Localization/test/UnitTests/RequestLocalizationOptionsExtensionsTest.cs @@ -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]); + } + } +} diff --git a/src/Middleware/Localization/testassets/LocalizationWebsite/LocalizationWebsite.csproj b/src/Middleware/Localization/testassets/LocalizationWebsite/LocalizationWebsite.csproj index 409af955a7..d9244e4330 100644 --- a/src/Middleware/Localization/testassets/LocalizationWebsite/LocalizationWebsite.csproj +++ b/src/Middleware/Localization/testassets/LocalizationWebsite/LocalizationWebsite.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0;net461 + netcoreapp3.0