Last active
November 21, 2017 16:13
-
-
Save jhorsman/679f6ab072c3896db41fcf893c3307b9 to your computer and use it in GitHub Desktop.
Inspect the Localization object with admin/sitelocalization action for DXA .NET. Put this action in your admin controller, and the view in the Views/Shared folder. Hostname/admin/sitelocalization will show the current loaded localizations. Hostname/admin/sitelocalization?refresh=true will force load all Localization.SiteLocalizations objects.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// put this in the AdminController which comes with DXA | |
using Sdl.Web.Common; | |
using Sdl.Web.Common.Configuration; | |
public ActionResult SiteLocalization(string expand = null) | |
{ | |
if (expand != null) | |
{ | |
foreach (Localization siteLocalization in WebRequestContext.Localization.SiteLocalizations) | |
{ | |
try | |
{ | |
siteLocalization.EnsureInitialized(); | |
} | |
catch (DxaItemNotFoundException) | |
{ | |
} | |
} | |
} | |
Localization localization = WebRequestContext.Localization; | |
return (ActionResult)this.View("SiteLocalization", localization); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace My.Dxa.Extensions | |
{ | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Newtonsoft.Json; | |
using Sdl.Web.Common.Configuration; | |
public static class LocalizationExtensions | |
{ | |
// inspired by Sdl.Web.Common.Configuration.GetConfigValue() | |
public static IDictionary<string, string> GetConfigValues(this Localization localization) | |
{ | |
IDictionary<string, string> configValues = new Dictionary<string, string>(); | |
IEnumerable<string> modules = localization.GetResources().Keys.Cast<string>().ToList().Select(k => k.Substring(0, k.LastIndexOf(".", StringComparison.Ordinal))).Distinct().OrderBy(s => s); | |
foreach (string module in modules) | |
{ | |
foreach (var configValue in LoadConfigSection(localization, module)) | |
{ | |
configValues.Add(module + "." + configValue.Key, configValue.Value); | |
} | |
} | |
return configValues; | |
} | |
// inspired by Sdl.Web.Common.Configuration.GetConfigValue() | |
public static IDictionary<string, string> GetConfigValues(this Localization localization, string sectionName) | |
{ | |
// inspired by ... | |
return LoadConfigSection(localization, sectionName); | |
} | |
// inspired by Sdl.Web.Common.Configuration.LoadConfigSection() | |
private static IDictionary<string, string> LoadConfigSection(Localization localization, string sectionName) | |
{ | |
string configItemUrl = string.Format("{0}/{1}/config/{2}.json", localization.Path, SiteConfiguration.SystemFolder, sectionName); | |
string configJson = SiteConfiguration.ContentProvider.GetStaticContentItem(configItemUrl, localization).GetText(); | |
IDictionary<string, string> configSection = JsonConvert.DeserializeObject<Dictionary<string, string>>(configJson); | |
return configSection; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@{ | |
Layout = ""; | |
} | |
@using My.Dxa.Extensions | |
@model Localization | |
<div> | |
<h1>Localization</h1> | |
<ul> | |
<li><strong>LocalizationId: @Model.LocalizationId</strong></li> | |
<li>Path: @Model.Path</li> | |
<li>Culture: @Model.Culture</li> | |
<li>Language: @Model.Language</li> | |
<li>StaticContentUrlPattern: @Model.StaticContentUrlPattern</li> | |
<li>IsStaging: @Model.IsStaging</li> | |
<li>IsHtmlDesignPublished: @Model.IsHtmlDesignPublished</li> | |
<li>Version: @Model.Version</li> | |
<li>LastRefresh: @Model.LastRefresh</li> | |
</ul> | |
<h2>Site Localizations</h2> | |
<ul> | |
@foreach (Localization siteLocalization in Model.SiteLocalizations) | |
{ | |
<li> | |
Site Localization | |
<ul> | |
<li><a href="@siteLocalization.Path/admin/sitelocalization"><strong>LocalizationId: @siteLocalization.LocalizationId</strong></a></li> | |
<li>Path: @siteLocalization.Path</li> | |
<li>Culture: @siteLocalization.Culture</li> | |
<li>Language: @siteLocalization.Language</li> | |
<li>StaticContentUrlPattern: @siteLocalization.StaticContentUrlPattern</li> | |
<li>IsStaging: @siteLocalization.IsStaging</li> | |
<li>IsHtmlDesignPublished: @siteLocalization.IsHtmlDesignPublished</li> | |
<li>Version: @siteLocalization.Version</li> | |
<li>LastRefresh: @siteLocalization.LastRefresh</li> | |
</ul> | |
</li> | |
} | |
</ul> | |
<h2>Resources</h2> | |
<ul> | |
@{ | |
var resources = Model.GetResources(); | |
var ordered = resources.Keys.Cast<string>().OrderBy(c => c.ToLower()); | |
} | |
@foreach (string key in ordered) | |
{ | |
<li>@key : @resources[key].ToString()</li> | |
} | |
</ul> | |
<h2>Configuration</h2> | |
<ul> | |
@foreach(var configValue in Model.GetConfigValues()) | |
{ | |
<li>@configValue.Key : @configValue.Value</li> | |
} | |
</ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment