From de7294335f61a17483f43ca45dbdc562e69326d3 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 13 May 2015 17:33:59 +1000 Subject: [PATCH] Adds nicer extensions for the Localize methods to not pass in a Culture and take the Culture from the current thread. Adds GUID Id display to the content/media/members editor --- .../LocalizedTextServiceExtensions.cs | 25 +++++++++++++++++++ .../readonlyvalue/readonlyvalue.html | 2 +- .../Models/Mapping/ContentModelMapper.cs | 15 ++++++----- .../Mapping/TabsAndPropertiesResolver.cs | 2 +- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs b/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs index 6ed20b2a45..292f8c585e 100644 --- a/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs +++ b/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Threading; namespace Umbraco.Core.Services { @@ -10,6 +11,30 @@ namespace Umbraco.Core.Services /// public static class LocalizedTextServiceExtensions { + /// + /// Localize using the current thread culture + /// + /// + /// + /// + /// + public static string Localize(this ILocalizedTextService manager, string key, string[] tokens) + { + return manager.Localize(key, Thread.CurrentThread.CurrentUICulture, tokens); + } + + /// + /// Localize using the current thread culture + /// + /// + /// + /// + /// + public static string Localize(this ILocalizedTextService manager, string key, IDictionary tokens = null) + { + return manager.Localize(key, Thread.CurrentThread.CurrentUICulture, tokens); + } + /// /// Localize a key without any variables /// diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/readonlyvalue/readonlyvalue.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/readonlyvalue/readonlyvalue.html index 84483c56a7..2dcf1b3d17 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/readonlyvalue/readonlyvalue.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/readonlyvalue/readonlyvalue.html @@ -1,3 +1,3 @@ 
- {{displayvalue}} +
\ No newline at end of file diff --git a/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs b/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs index 681c0c368d..7684636605 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.Linq; using System.Linq.Expressions; using System.Runtime.Serialization; +using System.Threading; using System.Web; using System.Web.Mvc; using System.Web.Routing; @@ -77,7 +78,7 @@ namespace Umbraco.Web.Models.Mapping .ForMember(display => display.Tabs, expression => expression.ResolveUsing()) .ForMember(display => display.AllowedActions, expression => expression.ResolveUsing( new ActionButtonsResolver(new Lazy(() => applicationContext.Services.UserService)))) - .AfterMap((media, display) => AfterMap(media, display, applicationContext.Services.DataTypeService)); + .AfterMap((media, display) => AfterMap(media, display, applicationContext.Services.DataTypeService, applicationContext.Services.TextService)); //FROM IContent TO ContentItemBasic config.CreateMap>() @@ -116,7 +117,9 @@ namespace Umbraco.Web.Models.Mapping /// /// /// - private static void AfterMap(IContent content, ContentItemDisplay display, IDataTypeService dataTypeService) + /// + /// + private static void AfterMap(IContent content, ContentItemDisplay display, IDataTypeService dataTypeService, ILocalizedTextService localizedText) { //map the tree node url if (HttpContext.Current != null) @@ -125,7 +128,7 @@ namespace Umbraco.Web.Models.Mapping var url = urlHelper.GetUmbracoApiService(controller => controller.GetTreeNode(display.Id.ToString(), null)); display.TreeNodeUrl = url; } - + //fill in the template config to be passed to the template drop down. var templateItemConfig = new Dictionary { { "", "Choose..." } }; foreach (var t in content.ContentType.AllowedTemplates @@ -144,14 +147,14 @@ namespace Umbraco.Web.Models.Mapping new ContentPropertyDisplay { Alias = string.Format("{0}releasedate", Constants.PropertyEditors.InternalGenericPropertiesPrefix), - Label = ui.Text("content", "releaseDate"), + Label = localizedText.Localize("content/releaseDate"), Value = display.ReleaseDate.HasValue ? display.ReleaseDate.Value.ToIsoString() : null, View = "datepicker" //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor }, new ContentPropertyDisplay { Alias = string.Format("{0}expiredate", Constants.PropertyEditors.InternalGenericPropertiesPrefix), - Label = ui.Text("content", "unpublishDate"), + Label = localizedText.Localize("content/unpublishDate"), Value = display.ExpireDate.HasValue ? display.ExpireDate.Value.ToIsoString() : null, View = "datepicker" //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor }, @@ -169,7 +172,7 @@ namespace Umbraco.Web.Models.Mapping new ContentPropertyDisplay { Alias = string.Format("{0}urls", Constants.PropertyEditors.InternalGenericPropertiesPrefix), - Label = ui.Text("content", "urls"), + Label = localizedText.Localize("content/urls"), Value = string.Join(",", display.Urls), View = "urllist" //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor }); diff --git a/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs b/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs index 8caae86dff..325b8df3e3 100644 --- a/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs @@ -65,7 +65,7 @@ namespace Umbraco.Web.Models.Mapping { Alias = string.Format("{0}id", Constants.PropertyEditors.InternalGenericPropertiesPrefix), Label = "Id", - Value = Convert.ToInt32(display.Id).ToInvariantString(), + Value = Convert.ToInt32(display.Id).ToInvariantString() + "
" + display.Key + "", View = labelEditor }, new ContentPropertyDisplay