// 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.AspNet.Mvc.Localization
{
///
/// This is an that provides localized HTML content.
///
/// 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 LocalizedString this[string key]
{
get
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return _localizer[key];
}
}
///
public virtual LocalizedString this[string key, params object[] arguments]
{
get
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return _localizer[key, arguments];
}
}
///
public virtual IHtmlLocalizer WithCulture(CultureInfo culture)
{
if (culture == null)
{
throw new ArgumentNullException(nameof(culture));
}
return _localizer.WithCulture(culture);
}
///
IStringLocalizer IStringLocalizer.WithCulture(CultureInfo culture)
{
if (culture == null)
{
throw new ArgumentNullException(nameof(culture));
}
return _localizer.WithCulture(culture);
}
///
public virtual LocalizedString GetString(string key)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return _localizer.GetString(key);
}
///
public virtual LocalizedString GetString(string key, params object[] arguments)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return _localizer.GetString(key, arguments);
}
///
public virtual LocalizedHtmlString Html(string key)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return _localizer.Html(key);
}
///
public virtual LocalizedHtmlString Html(string key, params object[] arguments)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return _localizer.Html(key, arguments);
}
///
public virtual IEnumerable GetAllStrings(bool includeAncestorCultures) =>
_localizer.GetAllStrings(includeAncestorCultures);
}
}