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

Commit

Permalink
Merge pull request #41 from frederikreher/localized-doctype-names
Browse files Browse the repository at this point in the history
fixed localization of doctype naming in overlay content type selector
  • Loading branch information
leekelleher authored Nov 16, 2018
2 parents d402014 + 5f7ccfb commit 413c060
Showing 1 changed file with 30 additions and 3 deletions.
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);
}
}
}

0 comments on commit 413c060

Please sign in to comment.