Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Sometimes we need to get additional keyFound variable to know if ResourceKey does not exist or exists but empty value #6267

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// 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.
Expand All @@ -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);

/// <summary>Saves a string to a resource file.</summary>
/// <param name="key">The key to save (e.g. "MyWidget.Text").</param>
/// <param name="value">The text value for the key.</param>
Expand Down
14 changes: 14 additions & 0 deletions DNN Platform/Library/Services/Localization/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,20 @@ public static string GetString(string key, string resourceFileRoot, PortalSettin
return LocalizationProvider.Instance.GetString(key, resourceFileRoot, language, portalSettings, disableShowMissingKeys);
}

/// <overloads>One of six overloads.</overloads>
/// <summary>GetString gets the localized string corresponding to the <paramref name="key"/>.</summary>
/// <param name="key">The resource key to find.</param>
/// <param name="resourceFileRoot">The Local Resource root.</param>
/// <param name="portalSettings">The current portals Portal Settings.</param>
/// <param name="language">A specific language to lookup the string.</param>
/// <param name="disableShowMissingKeys">Disables the show missing keys flag.</param>
/// <param name="keyFound">Returns whether a ResourceKey exists in the ResourceFile.</param>
/// <returns>The localized Text.</returns>
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);
}

/// <summary>GetStringUrl gets the localized string corresponding to the <paramref name="key"/>.</summary>
/// <param name="key">The resource key to find.</param>
/// <param name="resourceFileRoot">The Local Resource root.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public string GetString(string key, string resourceFileRoot, string language, Po

/// <inheritdoc/>
public string GetString(string key, string resourceFileRoot, string language, PortalSettings portalSettings, bool disableShowMissingKeys)
{
return this.GetString(key, resourceFileRoot, language, portalSettings, disableShowMissingKeys, out _);
}

/// <inheritdoc/>
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)
Expand All @@ -60,7 +66,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)
Expand Down