Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

fixed localization of doctype naming in overlay content type selector #41

Merged
merged 2 commits into from
Nov 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Newtonsoft.Json.Linq;
using Our.Umbraco.InnerContent.Helpers;
using Our.Umbraco.InnerContent.Web.WebApi.Filters;
using Umbraco.Core;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Services;
using Umbraco.Web.Editors;
using Umbraco.Web.Models.ContentEditing;
Expand All @@ -25,7 +27,7 @@ public IEnumerable<object> GetAllContentTypes()
{
id = x.Id,
guid = x.Key,
name = x.Name,
name = TranslateItem(x.Name),
alias = x.Alias,
icon = string.IsNullOrWhiteSpace(x.Icon) || x.Icon == ".sprTreeFolder" ? "icon-folder" : x.Icon,
tabs = x.CompositionPropertyGroups.Select(y => y.Name).Distinct()
Expand All @@ -45,7 +47,7 @@ public IEnumerable<object> GetContentTypesByGuid([ModelBinder] Guid[] guids)
// Umbraco core uses `localizedTextService.UmbracoDictionaryTranslate`, but this is currently marked as internal.
// https://github.com/umbraco/Umbraco-CMS/blob/release-7.7.0/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs#L76

name = ct.Name,
name = TranslateItem(ct.Name),
description = ct.Description,
guid = ct.Key,
key = ct.Key,
Expand All @@ -64,7 +66,7 @@ public IEnumerable<object> GetContentTypesByAlias([ModelBinder] string[] aliases
{
id = x.Id,
guid = x.Key,
name = x.Name,
name = TranslateItem(x.Name),
alias = x.Alias,
icon = string.IsNullOrWhiteSpace(x.Icon) || x.Icon == ".sprTreeFolder" ? "icon-folder" : x.Icon,
tabs = x.CompositionPropertyGroups.Select(y => y.Name).Distinct()
Expand Down Expand Up @@ -108,5 +110,30 @@ public SimpleNotificationModel CreateBlueprintFromContent([FromBody] JObject ite
Services.TextService.Localize("blueprints/createdBlueprintMessage", new[] { blueprint.Name }),
global::Umbraco.Web.UI.SpeechBubbleIcon.Success));
}

private static ICultureDictionary _cultureDictionary;
private static ICultureDictionary CultureDictionary
{
get
{
return
_cultureDictionary ??
(_cultureDictionary = CultureDictionaryFactoryResolver.Current.Factory.CreateDictionary());
}
}

public string TranslateItem(string text)
{
if (text == null)
{
return null;
}

if (text.StartsWith("#") == false)
return text;

text = text.Substring(1);
return CultureDictionary[text].IfNullOrWhiteSpace(text);
}
}
}