From 483b48c074962dfd69c45fb58912173789f22e7a Mon Sep 17 00:00:00 2001 From: OneDNN Date: Thu, 12 Dec 2024 14:47:56 +0700 Subject: [PATCH 1/2] Sometimes we need to get additional keyFound variable to know if ResourceKey does not exist or exists but empty value? --- .../Library/Services/Localization/LocalizationProvider.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/DNN Platform/Library/Services/Localization/LocalizationProvider.cs b/DNN Platform/Library/Services/Localization/LocalizationProvider.cs index 174b40bd9c0..42104226c73 100644 --- a/DNN Platform/Library/Services/Localization/LocalizationProvider.cs +++ b/DNN Platform/Library/Services/Localization/LocalizationProvider.cs @@ -52,6 +52,11 @@ public string GetString(string key, string resourceFileRoot, string language, Po /// public string GetString(string key, string resourceFileRoot, string language, PortalSettings portalSettings, bool disableShowMissingKeys) + { + return this.GetString(key, resourceFileRoot, language, portalSettings, disableShowMissingKeys, out _); + } + + public string GetString(string key, string resourceFileRoot, string language, PortalSettings portalSettings, bool disableShowMissingKeys, out bool keyFound) { // make the default translation property ".Text" if (key.IndexOf(".", StringComparison.Ordinal) < 1) @@ -60,7 +65,7 @@ public string GetString(string key, string resourceFileRoot, string language, Po } string resourceValue = Null.NullString; - bool keyFound = TryGetStringInternal(key, language, resourceFileRoot, portalSettings, ref resourceValue); + keyFound = TryGetStringInternal(key, language, resourceFileRoot, portalSettings, ref resourceValue); // If the key can't be found then it doesn't exist in the Localization Resources if (Localization.ShowMissingKeys && !disableShowMissingKeys) From 286aba91fd50f05c09ca71ce2d40dee7d416a616 Mon Sep 17 00:00:00 2001 From: OneDNN Date: Thu, 12 Dec 2024 15:10:39 +0700 Subject: [PATCH 2/2] Sometimes we need to get additional keyFound variable to know if ResourceKey does not exist or exists but empty value? --- .../Services/Localization/ILocalizationProvider.cs | 14 ++++++++------ .../Library/Services/Localization/Localization.cs | 14 ++++++++++++++ .../Services/Localization/LocalizationProvider.cs | 1 + 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/DNN Platform/Library/Services/Localization/ILocalizationProvider.cs b/DNN Platform/Library/Services/Localization/ILocalizationProvider.cs index df04c52f9ab..cb1a563f032 100644 --- a/DNN Platform/Library/Services/Localization/ILocalizationProvider.cs +++ b/DNN Platform/Library/Services/Localization/ILocalizationProvider.cs @@ -1,13 +1,13 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information - +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information + namespace DotNetNuke.Services.Localization { using System.Collections.Generic; - + using DotNetNuke.Entities.Portals; - + /// /// Do not implement. This interface is only implemented by the DotNetNuke core framework. Outside the framework it should used as a type and for unit test purposes only. /// There is no guarantee that this interface will not change. @@ -22,6 +22,8 @@ public interface ILocalizationProvider string GetString(string key, string resourceFileRoot, string language, PortalSettings portalSettings, bool disableShowMissingKeys); + string GetString(string key, string resourceFileRoot, string language, PortalSettings portalSettings, bool disableShowMissingKeys, out bool keyFound); + /// Saves a string to a resource file. /// The key to save (e.g. "MyWidget.Text"). /// The text value for the key. diff --git a/DNN Platform/Library/Services/Localization/Localization.cs b/DNN Platform/Library/Services/Localization/Localization.cs index 48b92417541..24823d9d69a 100644 --- a/DNN Platform/Library/Services/Localization/Localization.cs +++ b/DNN Platform/Library/Services/Localization/Localization.cs @@ -780,6 +780,20 @@ public static string GetString(string key, string resourceFileRoot, PortalSettin return LocalizationProvider.Instance.GetString(key, resourceFileRoot, language, portalSettings, disableShowMissingKeys); } + /// One of six overloads. + /// GetString gets the localized string corresponding to the . + /// The resource key to find. + /// The Local Resource root. + /// The current portals Portal Settings. + /// A specific language to lookup the string. + /// Disables the show missing keys flag. + /// Returns whether a ResourceKey exists in the ResourceFile. + /// The localized Text. + public static string GetString(string key, string resourceFileRoot, PortalSettings portalSettings, string language, bool disableShowMissingKeys, out bool keyFound) + { + return LocalizationProvider.Instance.GetString(key, resourceFileRoot, language, portalSettings, disableShowMissingKeys, out keyFound); + } + /// GetStringUrl gets the localized string corresponding to the . /// The resource key to find. /// The Local Resource root. diff --git a/DNN Platform/Library/Services/Localization/LocalizationProvider.cs b/DNN Platform/Library/Services/Localization/LocalizationProvider.cs index 42104226c73..a03e7ada73d 100644 --- a/DNN Platform/Library/Services/Localization/LocalizationProvider.cs +++ b/DNN Platform/Library/Services/Localization/LocalizationProvider.cs @@ -56,6 +56,7 @@ public string GetString(string key, string resourceFileRoot, string language, Po return this.GetString(key, resourceFileRoot, language, portalSettings, disableShowMissingKeys, out _); } + /// public string GetString(string key, string resourceFileRoot, string language, PortalSettings portalSettings, bool disableShowMissingKeys, out bool keyFound) { // make the default translation property ".Text"