diff --git a/src/Localization/Abstractions/ref/Microsoft.Extensions.Localization.Abstractions.netcoreapp.cs b/src/Localization/Abstractions/ref/Microsoft.Extensions.Localization.Abstractions.netcoreapp.cs index 8a5f5baa08..3b6186e98f 100644 --- a/src/Localization/Abstractions/ref/Microsoft.Extensions.Localization.Abstractions.netcoreapp.cs +++ b/src/Localization/Abstractions/ref/Microsoft.Extensions.Localization.Abstractions.netcoreapp.cs @@ -8,8 +8,6 @@ namespace Microsoft.Extensions.Localization Microsoft.Extensions.Localization.LocalizedString this[string name] { get; } Microsoft.Extensions.Localization.LocalizedString this[string name, params object[] arguments] { get; } System.Collections.Generic.IEnumerable GetAllStrings(bool includeParentCultures); - [System.ObsoleteAttribute("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")] - Microsoft.Extensions.Localization.IStringLocalizer WithCulture(System.Globalization.CultureInfo culture); } public partial interface IStringLocalizerFactory { @@ -43,7 +41,5 @@ namespace Microsoft.Extensions.Localization public virtual Microsoft.Extensions.Localization.LocalizedString this[string name] { get { throw null; } } public virtual Microsoft.Extensions.Localization.LocalizedString this[string name, params object[] arguments] { get { throw null; } } public System.Collections.Generic.IEnumerable GetAllStrings(bool includeParentCultures) { throw null; } - [System.ObsoleteAttribute("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")] - public virtual Microsoft.Extensions.Localization.IStringLocalizer WithCulture(System.Globalization.CultureInfo culture) { throw null; } } } diff --git a/src/Localization/Abstractions/ref/Microsoft.Extensions.Localization.Abstractions.netstandard2.0.cs b/src/Localization/Abstractions/ref/Microsoft.Extensions.Localization.Abstractions.netstandard2.0.cs index 8a5f5baa08..3b6186e98f 100644 --- a/src/Localization/Abstractions/ref/Microsoft.Extensions.Localization.Abstractions.netstandard2.0.cs +++ b/src/Localization/Abstractions/ref/Microsoft.Extensions.Localization.Abstractions.netstandard2.0.cs @@ -8,8 +8,6 @@ namespace Microsoft.Extensions.Localization Microsoft.Extensions.Localization.LocalizedString this[string name] { get; } Microsoft.Extensions.Localization.LocalizedString this[string name, params object[] arguments] { get; } System.Collections.Generic.IEnumerable GetAllStrings(bool includeParentCultures); - [System.ObsoleteAttribute("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")] - Microsoft.Extensions.Localization.IStringLocalizer WithCulture(System.Globalization.CultureInfo culture); } public partial interface IStringLocalizerFactory { @@ -43,7 +41,5 @@ namespace Microsoft.Extensions.Localization public virtual Microsoft.Extensions.Localization.LocalizedString this[string name] { get { throw null; } } public virtual Microsoft.Extensions.Localization.LocalizedString this[string name, params object[] arguments] { get { throw null; } } public System.Collections.Generic.IEnumerable GetAllStrings(bool includeParentCultures) { throw null; } - [System.ObsoleteAttribute("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")] - public virtual Microsoft.Extensions.Localization.IStringLocalizer WithCulture(System.Globalization.CultureInfo culture) { throw null; } } } diff --git a/src/Localization/Abstractions/src/IStringLocalizer.cs b/src/Localization/Abstractions/src/IStringLocalizer.cs index cabdf434ac..206092cd2d 100644 --- a/src/Localization/Abstractions/src/IStringLocalizer.cs +++ b/src/Localization/Abstractions/src/IStringLocalizer.cs @@ -35,13 +35,5 @@ namespace Microsoft.Extensions.Localization /// /// The strings. IEnumerable GetAllStrings(bool includeParentCultures); - - /// - /// Creates a new for a specific . - /// - /// The to use. - /// A culture-specific . - [Obsolete("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")] - IStringLocalizer WithCulture(CultureInfo culture); } } diff --git a/src/Localization/Abstractions/src/StringLocalizerOfT.cs b/src/Localization/Abstractions/src/StringLocalizerOfT.cs index 4190ca14ff..0f30ca6c87 100644 --- a/src/Localization/Abstractions/src/StringLocalizerOfT.cs +++ b/src/Localization/Abstractions/src/StringLocalizerOfT.cs @@ -29,10 +29,6 @@ namespace Microsoft.Extensions.Localization _localizer = factory.Create(typeof(TResourceSource)); } - /// - [Obsolete("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")] - public virtual IStringLocalizer WithCulture(CultureInfo culture) => _localizer.WithCulture(culture); - /// public virtual LocalizedString this[string name] { diff --git a/src/Localization/Localization/ref/Microsoft.Extensions.Localization.netcoreapp.cs b/src/Localization/Localization/ref/Microsoft.Extensions.Localization.netcoreapp.cs index 741e1ce106..dea13ee364 100644 --- a/src/Localization/Localization/ref/Microsoft.Extensions.Localization.netcoreapp.cs +++ b/src/Localization/Localization/ref/Microsoft.Extensions.Localization.netcoreapp.cs @@ -36,8 +36,6 @@ namespace Microsoft.Extensions.Localization public virtual System.Collections.Generic.IEnumerable GetAllStrings(bool includeParentCultures) { throw null; } protected System.Collections.Generic.IEnumerable GetAllStrings(bool includeParentCultures, System.Globalization.CultureInfo culture) { throw null; } protected string GetStringSafely(string name, System.Globalization.CultureInfo culture) { throw null; } - [System.ObsoleteAttribute("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")] - public Microsoft.Extensions.Localization.IStringLocalizer WithCulture(System.Globalization.CultureInfo culture) { throw null; } } public partial class ResourceManagerStringLocalizerFactory : Microsoft.Extensions.Localization.IStringLocalizerFactory { @@ -52,14 +50,6 @@ namespace Microsoft.Extensions.Localization protected virtual string GetResourcePrefix(string location, string baseName, string resourceLocation) { throw null; } protected virtual Microsoft.Extensions.Localization.RootNamespaceAttribute GetRootNamespaceAttribute(System.Reflection.Assembly assembly) { throw null; } } - [System.ObsoleteAttribute("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")] - public partial class ResourceManagerWithCultureStringLocalizer : Microsoft.Extensions.Localization.ResourceManagerStringLocalizer - { - public ResourceManagerWithCultureStringLocalizer(System.Resources.ResourceManager resourceManager, System.Reflection.Assembly resourceAssembly, string baseName, Microsoft.Extensions.Localization.IResourceNamesCache resourceNamesCache, System.Globalization.CultureInfo culture, Microsoft.Extensions.Logging.ILogger logger) : base (default(System.Resources.ResourceManager), default(System.Reflection.Assembly), default(string), default(Microsoft.Extensions.Localization.IResourceNamesCache), default(Microsoft.Extensions.Logging.ILogger)) { } - public override Microsoft.Extensions.Localization.LocalizedString this[string name] { get { throw null; } } - public override Microsoft.Extensions.Localization.LocalizedString this[string name, params object[] arguments] { get { throw null; } } - public override System.Collections.Generic.IEnumerable GetAllStrings(bool includeParentCultures) { throw null; } - } public partial class ResourceNamesCache : Microsoft.Extensions.Localization.IResourceNamesCache { public ResourceNamesCache() { } diff --git a/src/Localization/Localization/ref/Microsoft.Extensions.Localization.netstandard2.0.cs b/src/Localization/Localization/ref/Microsoft.Extensions.Localization.netstandard2.0.cs index 741e1ce106..dea13ee364 100644 --- a/src/Localization/Localization/ref/Microsoft.Extensions.Localization.netstandard2.0.cs +++ b/src/Localization/Localization/ref/Microsoft.Extensions.Localization.netstandard2.0.cs @@ -36,8 +36,6 @@ namespace Microsoft.Extensions.Localization public virtual System.Collections.Generic.IEnumerable GetAllStrings(bool includeParentCultures) { throw null; } protected System.Collections.Generic.IEnumerable GetAllStrings(bool includeParentCultures, System.Globalization.CultureInfo culture) { throw null; } protected string GetStringSafely(string name, System.Globalization.CultureInfo culture) { throw null; } - [System.ObsoleteAttribute("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")] - public Microsoft.Extensions.Localization.IStringLocalizer WithCulture(System.Globalization.CultureInfo culture) { throw null; } } public partial class ResourceManagerStringLocalizerFactory : Microsoft.Extensions.Localization.IStringLocalizerFactory { @@ -52,14 +50,6 @@ namespace Microsoft.Extensions.Localization protected virtual string GetResourcePrefix(string location, string baseName, string resourceLocation) { throw null; } protected virtual Microsoft.Extensions.Localization.RootNamespaceAttribute GetRootNamespaceAttribute(System.Reflection.Assembly assembly) { throw null; } } - [System.ObsoleteAttribute("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")] - public partial class ResourceManagerWithCultureStringLocalizer : Microsoft.Extensions.Localization.ResourceManagerStringLocalizer - { - public ResourceManagerWithCultureStringLocalizer(System.Resources.ResourceManager resourceManager, System.Reflection.Assembly resourceAssembly, string baseName, Microsoft.Extensions.Localization.IResourceNamesCache resourceNamesCache, System.Globalization.CultureInfo culture, Microsoft.Extensions.Logging.ILogger logger) : base (default(System.Resources.ResourceManager), default(System.Reflection.Assembly), default(string), default(Microsoft.Extensions.Localization.IResourceNamesCache), default(Microsoft.Extensions.Logging.ILogger)) { } - public override Microsoft.Extensions.Localization.LocalizedString this[string name] { get { throw null; } } - public override Microsoft.Extensions.Localization.LocalizedString this[string name, params object[] arguments] { get { throw null; } } - public override System.Collections.Generic.IEnumerable GetAllStrings(bool includeParentCultures) { throw null; } - } public partial class ResourceNamesCache : Microsoft.Extensions.Localization.IResourceNamesCache { public ResourceNamesCache() { } diff --git a/src/Localization/Localization/src/ResourceManagerStringLocalizer.cs b/src/Localization/Localization/src/ResourceManagerStringLocalizer.cs index a8321fca0a..4f13611a47 100644 --- a/src/Localization/Localization/src/ResourceManagerStringLocalizer.cs +++ b/src/Localization/Localization/src/ResourceManagerStringLocalizer.cs @@ -146,30 +146,6 @@ namespace Microsoft.Extensions.Localization } } - /// - /// Creates a new for a specific . - /// - /// The to use. - /// A culture-specific . - [Obsolete("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")] - public IStringLocalizer WithCulture(CultureInfo culture) - { - return culture == null - ? new ResourceManagerStringLocalizer( - _resourceManager, - _resourceStringProvider, - _resourceBaseName, - _resourceNamesCache, - _logger) - : new ResourceManagerWithCultureStringLocalizer( - _resourceManager, - _resourceStringProvider, - _resourceBaseName, - _resourceNamesCache, - culture, - _logger); - } - /// public virtual IEnumerable GetAllStrings(bool includeParentCultures) => GetAllStrings(includeParentCultures, CultureInfo.CurrentUICulture); diff --git a/src/Localization/Localization/src/ResourceManagerWithCultureStringLocalizer.cs b/src/Localization/Localization/src/ResourceManagerWithCultureStringLocalizer.cs deleted file mode 100644 index 2bc51289da..0000000000 --- a/src/Localization/Localization/src/ResourceManagerWithCultureStringLocalizer.cs +++ /dev/null @@ -1,165 +0,0 @@ -// 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 System.Collections.Generic; -using System.Globalization; -using System.Reflection; -using System.Resources; -using Microsoft.Extensions.Localization.Internal; -using Microsoft.Extensions.Logging; - -namespace Microsoft.Extensions.Localization -{ - /// - /// An that uses the and - /// to provide localized strings for a specific . - /// - [Obsolete("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")] - public class ResourceManagerWithCultureStringLocalizer : ResourceManagerStringLocalizer - { - private readonly string _resourceBaseName; - private readonly CultureInfo _culture; - - /// - /// Creates a new . - /// - /// The to read strings from. - /// The that can find the resources. - /// The base name of the embedded resource that contains the strings. - /// Cache of the list of strings for a given resource assembly name. - /// The specific to use. - /// The . - internal ResourceManagerWithCultureStringLocalizer( - ResourceManager resourceManager, - IResourceStringProvider resourceStringProvider, - string baseName, - IResourceNamesCache resourceNamesCache, - CultureInfo culture, - ILogger logger) - : base(resourceManager, resourceStringProvider, baseName, resourceNamesCache, logger) - { - if (resourceManager == null) - { - throw new ArgumentNullException(nameof(resourceManager)); - } - - if (resourceStringProvider == null) - { - throw new ArgumentNullException(nameof(resourceStringProvider)); - } - - if (baseName == null) - { - throw new ArgumentNullException(nameof(baseName)); - } - - if (resourceNamesCache == null) - { - throw new ArgumentNullException(nameof(resourceNamesCache)); - } - - if (culture == null) - { - throw new ArgumentNullException(nameof(culture)); - } - - if (logger == null) - { - throw new ArgumentNullException(nameof(logger)); - } - - _resourceBaseName = baseName; - _culture = culture; - } - - /// - /// Creates a new . - /// - /// The to read strings from. - /// The that contains the strings as embedded resources. - /// The base name of the embedded resource that contains the strings. - /// Cache of the list of strings for a given resource assembly name. - /// The specific to use. - /// The . - public ResourceManagerWithCultureStringLocalizer( - ResourceManager resourceManager, - Assembly resourceAssembly, - string baseName, - IResourceNamesCache resourceNamesCache, - CultureInfo culture, - ILogger logger) - : base(resourceManager, resourceAssembly, baseName, resourceNamesCache, logger) - { - if (resourceManager == null) - { - throw new ArgumentNullException(nameof(resourceManager)); - } - - if (resourceAssembly == null) - { - throw new ArgumentNullException(nameof(resourceAssembly)); - } - - if (baseName == null) - { - throw new ArgumentNullException(nameof(baseName)); - } - - if (resourceNamesCache == null) - { - throw new ArgumentNullException(nameof(resourceNamesCache)); - } - - if (culture == null) - { - throw new ArgumentNullException(nameof(culture)); - } - - if (logger == null) - { - throw new ArgumentNullException(nameof(logger)); - } - - _resourceBaseName = baseName; - _culture = culture; - } - - /// - public override LocalizedString this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException(nameof(name)); - } - - var value = GetStringSafely(name, _culture); - - return new LocalizedString(name, value ?? name, resourceNotFound: value == null, searchedLocation: _resourceBaseName); - } - } - - /// - public override LocalizedString this[string name, params object[] arguments] - { - get - { - if (name == null) - { - throw new ArgumentNullException(nameof(name)); - } - - var format = GetStringSafely(name, _culture); - var value = string.Format(_culture, format ?? name, arguments); - - return new LocalizedString(name, value, resourceNotFound: format == null, searchedLocation: _resourceBaseName); - } - } - - /// - public override IEnumerable GetAllStrings(bool includeParentCultures) => - GetAllStrings(includeParentCultures, _culture); - } -} diff --git a/src/Localization/Localization/test/Microsoft.Extensions.Localization.Tests/StringLocalizerOfTTest.cs b/src/Localization/Localization/test/Microsoft.Extensions.Localization.Tests/StringLocalizerOfTTest.cs index ce06e74d1c..53d290064e 100644 --- a/src/Localization/Localization/test/Microsoft.Extensions.Localization.Tests/StringLocalizerOfTTest.cs +++ b/src/Localization/Localization/test/Microsoft.Extensions.Localization.Tests/StringLocalizerOfTTest.cs @@ -33,28 +33,6 @@ namespace Microsoft.Extensions.Localization factory.Verify(mock => mock.Create(typeof(object)), Times.Once()); } - [Fact] - public void WithCulture_InvokesWithCultureFromInnerLocalizer() - { - // Arrange - var factory = new Mock(); - var innerLocalizer = new Mock(); - factory.Setup(mock => mock.Create(typeof(object))) - .Returns(innerLocalizer.Object); - - var localizer = new StringLocalizer(factory.Object); - - // Act -#pragma warning disable CS0618 - localizer.WithCulture(CultureInfo.GetCultureInfo("fr-FR")); -#pragma warning restore CS0618 - - // Assert -#pragma warning disable CS0618 - innerLocalizer.Verify(mock => mock.WithCulture(CultureInfo.GetCultureInfo("fr-FR")), Times.Once()); -#pragma warning restore CS0618 - } - [Fact] public void Indexer_ThrowsAnExceptionForNullName() {