From e7baa0878878bded2d92a6e48f535e91331244e6 Mon Sep 17 00:00:00 2001
From: nzdev <834725+nzdev@users.noreply.github.com>
Date: Sat, 6 Feb 2021 23:17:15 +1300
Subject: [PATCH] Improve getAllStoredValues.
---
.../Services/ILocalizedTextService.cs | 7 +++++++
.../Implement/LocalizedTextService.cs | 21 ++++++++++++++++---
.../Editors/BackOfficeController.cs | 7 +++++++
3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/src/Umbraco.Core/Services/ILocalizedTextService.cs b/src/Umbraco.Core/Services/ILocalizedTextService.cs
index a4e5141a42..73212546a5 100644
--- a/src/Umbraco.Core/Services/ILocalizedTextService.cs
+++ b/src/Umbraco.Core/Services/ILocalizedTextService.cs
@@ -16,6 +16,13 @@ namespace Umbraco.Core.Services
/// This can be null
///
string Localize(string area, string alias, CultureInfo culture, IDictionary tokens = null);
+
+
+ ///
+ /// Returns all key/values in storage for the given culture
+ ///
+ ///
+ IDictionary> GetAllStoredValuesByAreaAndAlias(CultureInfo culture);
}
///
diff --git a/src/Umbraco.Core/Services/Implement/LocalizedTextService.cs b/src/Umbraco.Core/Services/Implement/LocalizedTextService.cs
index c10ae59907..79c568e374 100644
--- a/src/Umbraco.Core/Services/Implement/LocalizedTextService.cs
+++ b/src/Umbraco.Core/Services/Implement/LocalizedTextService.cs
@@ -145,15 +145,15 @@ namespace Umbraco.Core.Services.Implement
// TODO: Hack, see notes on ConvertToSupportedCultureWithRegionCode
culture = ConvertToSupportedCultureWithRegionCode(culture);
- var result = new Dictionary();
+
if (_dictionarySource.ContainsKey(culture) == false)
{
_logger.Warn("The culture specified {Culture} was not found in any configured sources for this service", culture);
- return result;
+ return new Dictionary(0);
}
-
+ IDictionary result = new Dictionary();
//convert all areas + keys to a single key with a '/'
foreach (var area in _dictionarySource[culture])
{
@@ -309,5 +309,20 @@ namespace Umbraco.Core.Services.Implement
return value;
}
+ public IDictionary> GetAllStoredValuesByAreaAndAlias(CultureInfo culture)
+ {
+ if (culture == null) throw new ArgumentNullException("culture");
+
+ // TODO: Hack, see notes on ConvertToSupportedCultureWithRegionCode
+ culture = ConvertToSupportedCultureWithRegionCode(culture);
+
+ if (_dictionarySource.ContainsKey(culture) == false)
+ {
+ _logger.Warn("The culture specified {Culture} was not found in any configured sources for this service", culture);
+ return new Dictionary>(0);
+ }
+
+ return _dictionarySource[culture];
+ }
}
}
diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs
index 46bd52978d..5da0cd0cc3 100644
--- a/src/Umbraco.Web/Editors/BackOfficeController.cs
+++ b/src/Umbraco.Web/Editors/BackOfficeController.cs
@@ -207,6 +207,13 @@ namespace Umbraco.Web.Editors
: CultureInfo.GetCultureInfo(GlobalSettings.DefaultUILanguage)
: CultureInfo.GetCultureInfo(culture);
+
+ if(Services.TextService is ILocalizedTextService2 localizedText2)
+ {
+ var nestedDictionary2 = localizedText2.GetAllStoredValuesByAreaAndAlias(cultureInfo);
+ return new JsonNetResult { Data = nestedDictionary2, Formatting = Formatting.None };
+ }
+
var allValues = Services.TextService.GetAllStoredValues(cultureInfo);
var pathedValues = allValues.Select(kv =>
{