From f330c4fcb60c7875d0d18a64fc51ea05112f5f7e Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Wed, 16 Jun 2021 22:16:48 -0400 Subject: [PATCH] add extension method for Localization which allows specification of key and value --- .../OqtaneLocalizationExtensions.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Oqtane.Client/Extensions/OqtaneLocalizationExtensions.cs diff --git a/Oqtane.Client/Extensions/OqtaneLocalizationExtensions.cs b/Oqtane.Client/Extensions/OqtaneLocalizationExtensions.cs new file mode 100644 index 00000000..6ee9c1eb --- /dev/null +++ b/Oqtane.Client/Extensions/OqtaneLocalizationExtensions.cs @@ -0,0 +1,22 @@ +namespace Microsoft.Extensions.Localization +{ + public static class OqtaneLocalizationExtensions + { + /// + /// Gets the string resource for the specified key and returns the value if the resource does not exist + /// + /// + /// the static key used to identify the string resource + /// the default value if the resource for the static key does not exist + /// + public static string GetString(this IStringLocalizer localizer, string key, string value) + { + string localizedValue = localizer[key]; + if (localizedValue == key) // not localized + { + localizedValue = value; + } + return localizedValue; + } + } +}