add extension method for Localization which allows specification of key and value

This commit is contained in:
Shaun Walker 2021-06-16 22:16:48 -04:00
parent d32b622f7e
commit f330c4fcb6

View File

@ -0,0 +1,22 @@
namespace Microsoft.Extensions.Localization
{
public static class OqtaneLocalizationExtensions
{
/// <summary>
/// Gets the string resource for the specified key and returns the value if the resource does not exist
/// </summary>
/// <param name="localizer"></param>
/// <param name="key">the static key used to identify the string resource</param>
/// <param name="value">the default value if the resource for the static key does not exist</param>
/// <returns></returns>
public static string GetString(this IStringLocalizer localizer, string key, string value)
{
string localizedValue = localizer[key];
if (localizedValue == key) // not localized
{
localizedValue = value;
}
return localizedValue;
}
}
}