// 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.Collections.Generic; using System.Globalization; using System.Reflection; using System.Resources; using Microsoft.Framework.Internal; using Microsoft.Framework.Localization.Internal; namespace Microsoft.Framework.Localization { /// /// An that uses the and /// to provide localized strings for a specific . /// public class ResourceManagerWithCultureStringLocalizer : ResourceManagerStringLocalizer { private readonly CultureInfo _culture; /// /// Creates a new . /// /// The to read strings from. /// The that contains the strings as embedded resources. /// The base name of the embedded resource in the that contains the strings. /// The specific to use. public ResourceManagerWithCultureStringLocalizer( [NotNull] ResourceManager resourceManager, [NotNull] Assembly assembly, [NotNull] string baseName, [NotNull] CultureInfo culture) : base(resourceManager, assembly, baseName) { _culture = culture; } /// /// Intended for testing purposes only. /// public ResourceManagerWithCultureStringLocalizer( [NotNull] ResourceManager resourceManager, [NotNull] AssemblyWrapper assemblyWrapper, [NotNull] string baseName, [NotNull] CultureInfo culture) : base(resourceManager, assemblyWrapper, baseName) { _culture = culture; } /// public override LocalizedString this[[NotNull] string name] { get { var value = GetStringSafely(name, _culture); return new LocalizedString(name, value ?? name); } } /// public override LocalizedString this[[NotNull] string name, params object[] arguments] { get { var format = GetStringSafely(name, _culture); var value = string.Format(_culture, format ?? name, arguments); return new LocalizedString(name, value ?? name, resourceNotFound: format == null); } } /// public override IEnumerator GetEnumerator() { return GetEnumerator(_culture); } } }