// 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;
namespace Microsoft.Extensions.Localization
{
public static class StringLocalizerExtensions
{
///
/// Gets the string resource with the given name.
///
/// The .
/// The name of the string resource.
/// The string resource as a .
public static LocalizedString GetString(
this IStringLocalizer stringLocalizer,
string name)
{
if (stringLocalizer == null)
{
throw new ArgumentNullException(nameof(stringLocalizer));
}
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return stringLocalizer[name];
}
///
/// Gets the string resource with the given name and formatted with the supplied arguments.
///
/// The .
/// The name of the string resource.
/// The values to format the string with.
/// The formatted string resource as a .
public static LocalizedString GetString(
this IStringLocalizer stringLocalizer,
string name,
params object[] arguments)
{
if (stringLocalizer == null)
{
throw new ArgumentNullException(nameof(stringLocalizer));
}
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return stringLocalizer[name, arguments];
}
///
/// Gets all string resources including those for ancestor cultures.
///
/// The .
/// The string resources.
public static IEnumerable GetAllStrings(this IStringLocalizer stringLocalizer)
{
if (stringLocalizer == null)
{
throw new ArgumentNullException(nameof(stringLocalizer));
}
return stringLocalizer.GetAllStrings(includeAncestorCultures: true);
}
}
}