// 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 Microsoft.Extensions.Localization;
namespace Microsoft.AspNetCore.Mvc.Localization
{
///
/// An implementation that provides localized HTML content for the specified type
/// .
///
/// The to scope the resource names.
public class HtmlLocalizer : IHtmlLocalizer
{
private readonly IHtmlLocalizer _localizer;
///
/// Creates a new .
///
/// The .
public HtmlLocalizer(IHtmlLocalizerFactory factory)
{
_localizer = factory.Create(typeof(TResource));
}
///
public virtual LocalizedHtmlString this[string name]
{
get
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return _localizer[name];
}
}
///
public virtual LocalizedHtmlString this[string name, params object[] arguments]
{
get
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return _localizer[name, arguments];
}
}
///
public virtual LocalizedString GetString(string name)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return _localizer.GetString(name);
}
///
public virtual LocalizedString GetString(string name, params object[] arguments)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return _localizer.GetString(name, arguments);
}
///
public virtual IEnumerable GetAllStrings(bool includeParentCultures) =>
_localizer.GetAllStrings(includeParentCultures);
///
public virtual IHtmlLocalizer WithCulture(CultureInfo culture)
{
if (culture == null)
{
throw new ArgumentNullException(nameof(culture));
}
return _localizer.WithCulture(culture);
}
}
}