Moved methods off of IStringLocalizer and into extension methods
This commit is contained in:
parent
ecfb7f342a
commit
2ba7049648
|
|
@ -26,21 +26,6 @@ namespace Microsoft.Framework.Localization
|
||||||
/// <returns>The formatted string resource as a <see cref="LocalizedString"/>.</returns>
|
/// <returns>The formatted string resource as a <see cref="LocalizedString"/>.</returns>
|
||||||
LocalizedString this[string name, params object[] arguments] { get; }
|
LocalizedString this[string name, params object[] arguments] { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the string resource with the given name.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The name of the string resource.</param>
|
|
||||||
/// <returns>The string resource as a <see cref="LocalizedString"/>.</returns>
|
|
||||||
LocalizedString GetString(string name);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the string resource with the given name and formatted with the supplied arguments.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The name of the string resource.</param>
|
|
||||||
/// <param name="arguments">The values to format the string with.</param>
|
|
||||||
/// <returns>The formatted string resource as a <see cref="LocalizedString"/>.</returns>
|
|
||||||
LocalizedString GetString(string name, params object[] arguments);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="ResourceManagerStringLocalizer"/> for a specific <see cref="CultureInfo"/>.
|
/// Creates a new <see cref="ResourceManagerStringLocalizer"/> for a specific <see cref="CultureInfo"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace Microsoft.Framework.Localization
|
||||||
|
{
|
||||||
|
public static class IStringLocalizerExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the string resource with the given name.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name of the string resource.</param>
|
||||||
|
/// <returns>The string resource as a <see cref="LocalizedString"/>.</returns>
|
||||||
|
public static LocalizedString GetString(this IStringLocalizer stringLocalizer, string name)
|
||||||
|
{
|
||||||
|
return stringLocalizer[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the string resource with the given name and formatted with the supplied arguments.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name of the string resource.</param>
|
||||||
|
/// <param name="arguments">The values to format the string with.</param>
|
||||||
|
/// <returns>The formatted string resource as a <see cref="LocalizedString"/>.</returns>
|
||||||
|
public static LocalizedString GetString(this IStringLocalizer stringLocalizer, string name, params object[] arguments)
|
||||||
|
{
|
||||||
|
return stringLocalizer[name, arguments];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -53,24 +53,24 @@ namespace Microsoft.Framework.Localization
|
||||||
protected string ResourceBaseName { get; }
|
protected string ResourceBaseName { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual LocalizedString this[[NotNull] string name] => GetString(name);
|
public virtual LocalizedString this[[NotNull] string name]
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public virtual LocalizedString this[[NotNull] string name, params object[] arguments] => GetString(name, arguments);
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public virtual LocalizedString GetString([NotNull] string name)
|
|
||||||
{
|
{
|
||||||
var value = GetStringSafely(name, null);
|
get
|
||||||
return new LocalizedString(name, value ?? name, resourceNotFound: value == null);
|
{
|
||||||
|
var value = GetStringSafely(name, null);
|
||||||
|
return new LocalizedString(name, value ?? name, resourceNotFound: value == null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual LocalizedString GetString([NotNull] string name, params object[] arguments)
|
public virtual LocalizedString this[[NotNull] string name, params object[] arguments]
|
||||||
{
|
{
|
||||||
var format = GetStringSafely(name, null);
|
get
|
||||||
var value = string.Format(format ?? name, arguments);
|
{
|
||||||
return new LocalizedString(name, value, resourceNotFound: format == null);
|
var format = GetStringSafely(name, null);
|
||||||
|
var value = string.Format(format ?? name, arguments);
|
||||||
|
return new LocalizedString(name, value, resourceNotFound: format == null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -36,24 +36,24 @@ namespace Microsoft.Framework.Localization
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override LocalizedString this[[NotNull] string name] => GetString(name);
|
public override LocalizedString this[[NotNull] string name]
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override LocalizedString this[[NotNull] string name, params object[] arguments] => GetString(name, arguments);
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override LocalizedString GetString([NotNull] string name)
|
|
||||||
{
|
{
|
||||||
var value = GetStringSafely(name, _culture);
|
get
|
||||||
return new LocalizedString(name, value ?? name);
|
{
|
||||||
|
var value = GetStringSafely(name, _culture);
|
||||||
|
return new LocalizedString(name, value ?? name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override LocalizedString GetString([NotNull] string name, params object[] arguments)
|
public override LocalizedString this[[NotNull] string name, params object[] arguments]
|
||||||
{
|
{
|
||||||
var format = GetStringSafely(name, _culture);
|
get
|
||||||
var value = string.Format(_culture, format ?? name, arguments);
|
{
|
||||||
return new LocalizedString(name, value ?? name, resourceNotFound: format == null);
|
var format = GetStringSafely(name, _culture);
|
||||||
|
var value = string.Format(_culture, format ?? name, arguments);
|
||||||
|
return new LocalizedString(name, value ?? name, resourceNotFound: format == null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue