csharp 使用DXA .NET的admin / sitelocalization操作检查Localization对象。将此操作放在管理控制器中,将视图放在t中

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 使用DXA .NET的admin / sitelocalization操作检查Localization对象。将此操作放在管理控制器中,将视图放在t中相关的知识,希望对你有一定的参考价值。

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

以上是关于csharp 使用DXA .NET的admin / sitelocalization操作检查Localization对象。将此操作放在管理控制器中,将视图放在t中的主要内容,如果未能解决你的问题,请参考以下文章

csharp 最小的DXA 1.6核心区域注册。如果没有这个,DXA webapp就无法使用框架控制器。那些控制器不在c中

csharp 最小的DXA 1.6核心区域注册。如果没有这个,DXA webapp就无法使用框架控制器。那些控制器不在c中

java 在DXA Java中使用模块配置

java 在DXA Java中使用模块配置

java 在没有Web请求的情况下使用DXA 1.7 ContentProvider和Localization。

powershell 获取所有DXA应用程序数据。