add extension method for Localization which allows specification of key and value
This commit is contained in:
parent
d32b622f7e
commit
f330c4fcb6
22
Oqtane.Client/Extensions/OqtaneLocalizationExtensions.cs
Normal file
22
Oqtane.Client/Extensions/OqtaneLocalizationExtensions.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user