jhorsman
2/17/2017 - 7:49 AM

Inspect the Localization object with admin/sitelocalization action for DXA .NET. Put this action in your admin controller, and the view in t

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.

@{
    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>
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;
        }
    }
}
// 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);
        }