diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs
index 429b2e625a..d776749e6b 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs
@@ -1,9 +1,18 @@
-using System.Threading.Tasks;
+using System;
+using System.Globalization;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
+using Newtonsoft.Json;
+using Umbraco.Core;
using Umbraco.Core.Configuration;
+using Umbraco.Core.Configuration.Grid;
using Umbraco.Core.Hosting;
+using Umbraco.Core.Services;
using Umbraco.Core.WebAssets;
using Umbraco.Net;
+using Umbraco.Web.BackOffice.ActionResults;
using Umbraco.Web.BackOffice.Filters;
using Umbraco.Web.Common.ActionResults;
using Umbraco.Web.WebAssets;
@@ -16,13 +25,19 @@ namespace Umbraco.Web.BackOffice.Controllers
private readonly IGlobalSettings _globalSettings;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime;
+ private readonly IUmbracoContextAccessor _umbracoContextAccessor;
+ private readonly ILocalizedTextService _textService;
+ private readonly IGridConfig _gridConfig;
- public BackOfficeController(IRuntimeMinifier runtimeMinifier, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IUmbracoApplicationLifetime umbracoApplicationLifetime)
+ public BackOfficeController(IRuntimeMinifier runtimeMinifier, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IUmbracoApplicationLifetime umbracoApplicationLifetime, IUmbracoContextAccessor umbracoContextAccessor, ILocalizedTextService textService, IGridConfig gridConfig)
{
_runtimeMinifier = runtimeMinifier;
_globalSettings = globalSettings;
_hostingEnvironment = hostingEnvironment;
_umbracoApplicationLifetime = umbracoApplicationLifetime;
+ _umbracoContextAccessor = umbracoContextAccessor;
+ _textService = textService;
+ _gridConfig = gridConfig ?? throw new ArgumentNullException(nameof(gridConfig));
}
// GET
@@ -42,5 +57,53 @@ namespace Umbraco.Web.BackOffice.Controllers
return new JavaScriptResult(result);
}
+
+ ///
+ /// Get the json localized text for a given culture or the culture for the current user
+ ///
+ ///
+ ///
+ [HttpGet]
+ public JsonNetResult LocalizedText(string culture = null)
+ {
+ var securityHelper = _umbracoContextAccessor.GetRequiredUmbracoContext().Security;
+ var isAuthenticated = securityHelper.IsAuthenticated();
+
+ var cultureInfo = string.IsNullOrWhiteSpace(culture)
+ //if the user is logged in, get their culture, otherwise default to 'en'
+ ? isAuthenticated
+ //current culture is set at the very beginning of each request
+ ? Thread.CurrentThread.CurrentCulture
+ : CultureInfo.GetCultureInfo(_globalSettings.DefaultUILanguage)
+ : CultureInfo.GetCultureInfo(culture);
+
+ var allValues = _textService.GetAllStoredValues(cultureInfo);
+ var pathedValues = allValues.Select(kv =>
+ {
+ var slashIndex = kv.Key.IndexOf('/');
+ var areaAlias = kv.Key.Substring(0, slashIndex);
+ var valueAlias = kv.Key.Substring(slashIndex + 1);
+ return new
+ {
+ areaAlias,
+ valueAlias,
+ value = kv.Value
+ };
+ });
+
+ var nestedDictionary = pathedValues
+ .GroupBy(pv => pv.areaAlias)
+ .ToDictionary(pv => pv.Key, pv =>
+ pv.ToDictionary(pve => pve.valueAlias, pve => pve.value));
+
+ return new JsonNetResult { Data = nestedDictionary, Formatting = Formatting.None };
+ }
+
+ //[UmbracoAuthorize(Order = 0)] TODO: Re-implement UmbracoAuthorizeAttribute
+ [HttpGet]
+ public JsonNetResult GetGridConfig()
+ {
+ return new JsonNetResult { Data = _gridConfig.EditorsConfig.Editors, Formatting = Formatting.None };
+ }
}
}
diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs
index 7e3638d96a..825b67767a 100644
--- a/src/Umbraco.Web/Editors/BackOfficeController.cs
+++ b/src/Umbraco.Web/Editors/BackOfficeController.cs
@@ -194,6 +194,7 @@ namespace Umbraco.Web.Editors
///
///
///
+ /// Migrated already to .Net Core
[HttpGet]
public JsonNetResult LocalizedText(string culture = null)
{
@@ -239,7 +240,8 @@ namespace Umbraco.Web.Editors
return JavaScript(result);
}
-
+
+ /// Migrated already to .Net Core
[UmbracoAuthorize(Order = 0)]
[HttpGet]
public JsonNetResult GetGridConfig()