From b268f76aa9c4d21b0701e23dec6a111baf403812 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 19 May 2016 19:20:49 +0200 Subject: [PATCH] Removes umbraco.cms.businesslogic.Dictionary !!! --- .../Models/DictionaryItemExtensions.cs | 30 ++ .../Models/UmbracoEntityExtensions.cs | 1 - src/Umbraco.Core/Umbraco.Core.csproj | 1 + .../umbraco.presentation/library.cs | 15 +- .../umbraco/create/dictionaryTasks.cs | 20 +- .../developer/Packages/editPackage.aspx.cs | 14 +- .../Packages/installedPackage.aspx.cs | 12 +- .../settings/DictionaryItemList.aspx.cs | 24 +- .../settings/EditDictionaryItem.aspx.cs | 36 +- src/umbraco.cms/businesslogic/ContentType.cs | 26 +- src/umbraco.cms/businesslogic/Dictionary.cs | 395 ------------------ .../PackageInstance/CreatedPackage.cs | 6 +- .../propertytype/propertytype.cs | 15 +- .../businesslogic/template/Template.cs | 9 +- src/umbraco.cms/umbraco.cms.csproj | 3 - 15 files changed, 139 insertions(+), 468 deletions(-) create mode 100644 src/Umbraco.Core/Models/DictionaryItemExtensions.cs delete mode 100644 src/umbraco.cms/businesslogic/Dictionary.cs diff --git a/src/Umbraco.Core/Models/DictionaryItemExtensions.cs b/src/Umbraco.Core/Models/DictionaryItemExtensions.cs new file mode 100644 index 0000000000..71bb663d2e --- /dev/null +++ b/src/Umbraco.Core/Models/DictionaryItemExtensions.cs @@ -0,0 +1,30 @@ +using System.Linq; + +namespace Umbraco.Core.Models +{ + public static class DictionaryItemExtensions + { + /// + /// Returns the translation value for the language id, if no translation is found it returns an empty string + /// + /// + /// + /// + public static string GetTranslatedValue(this IDictionaryItem d, int languageId) + { + var trans = d.Translations.FirstOrDefault(x => x.LanguageId == languageId); + return trans == null ? string.Empty : trans.Value; + } + + /// + /// Returns the default translated value based on the default language + /// + /// + /// + public static string GetDefaultValue(this IDictionaryItem d) + { + var defaultTranslation = d.Translations.FirstOrDefault(x => x.Language.Id == 1); + return defaultTranslation == null ? string.Empty : defaultTranslation.Value; + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/UmbracoEntityExtensions.cs b/src/Umbraco.Core/Models/UmbracoEntityExtensions.cs index 987be2a276..d0932e2b26 100644 --- a/src/Umbraco.Core/Models/UmbracoEntityExtensions.cs +++ b/src/Umbraco.Core/Models/UmbracoEntityExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web.UI.WebControls; diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index e31ae0bed8..74da2c48a4 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -335,6 +335,7 @@ True Files.resx + diff --git a/src/Umbraco.Web/umbraco.presentation/library.cs b/src/Umbraco.Web/umbraco.presentation/library.cs index 4559fc370f..93157f383d 100644 --- a/src/Umbraco.Web/umbraco.presentation/library.cs +++ b/src/Umbraco.Web/umbraco.presentation/library.cs @@ -1257,23 +1257,28 @@ namespace umbraco //int languageId = GetCurrentLanguageId(); int languageId = Language.GetByCultureCode(System.Threading.Thread.CurrentThread.CurrentUICulture.Name).id; - Dictionary.DictionaryItem di = new Dictionary.DictionaryItem(Key); + var di = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemByKey(Key); + if (di == null) + { + return xd.CreateNavigator().Select("/"); + } - foreach (Dictionary.DictionaryItem item in di.Children) + var children = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemChildren(di.Key); + foreach (var item in children) { XmlNode xe; try { if (languageId != 0) - xe = XmlHelper.AddTextNode(xd, "DictionaryItem", item.Value(languageId)); + xe = XmlHelper.AddTextNode(xd, "DictionaryItem", item.GetTranslatedValue(languageId)); else - xe = XmlHelper.AddTextNode(xd, "DictionaryItem", item.Value()); + xe = XmlHelper.AddTextNode(xd, "DictionaryItem", item.GetDefaultValue()); } catch { xe = XmlHelper.AddTextNode(xd, "DictionaryItem", string.Empty); } - xe.Attributes.Append(XmlHelper.AddAttribute(xd, "key", item.key)); + xe.Attributes.Append(XmlHelper.AddAttribute(xd, "key", item.ItemKey)); xd.DocumentElement.AppendChild(xe); } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/dictionaryTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/dictionaryTasks.cs index 14840a6913..d85806202c 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/dictionaryTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/dictionaryTasks.cs @@ -1,3 +1,4 @@ +using System; using Umbraco.Core.Logging; using Umbraco.Web.UI; using Umbraco.Core; @@ -10,27 +11,32 @@ namespace umbraco public override bool PerformSave() { //check to see if key is already there - if (cms.businesslogic.Dictionary.DictionaryItem.hasKey(Alias)) + if (ApplicationContext.Current.Services.LocalizationService.DictionaryItemExists(Alias)) return false; // Create new dictionary item if name no already exist if (ParentID > 0) { - var id = cms.businesslogic.Dictionary.DictionaryItem.addKey(Alias, "", new cms.businesslogic.Dictionary.DictionaryItem(ParentID).key); - _returnUrl = string.Format("settings/editDictionaryItem.aspx?id={0}", id); + var di = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemById(ParentID); + if (di == null) throw new NullReferenceException("No dictionary item found by id " + ParentID); + var item = ApplicationContext.Current.Services.LocalizationService.CreateDictionaryItemWithIdentity(Alias, di.Key); + _returnUrl = string.Format("settings/editDictionaryItem.aspx?id={0}", item.Id); } else { - var id = cms.businesslogic.Dictionary.DictionaryItem.addKey(Alias, ""); - _returnUrl = string.Format("settings/editDictionaryItem.aspx?id={0}", id); + var item = ApplicationContext.Current.Services.LocalizationService.CreateDictionaryItemWithIdentity(Alias, null); + _returnUrl = string.Format("settings/editDictionaryItem.aspx?id={0}", item.Id); } return true; } public override bool PerformDelete() { - LogHelper.Debug(TypeID.ToString() + " " + ParentID.ToString() + " deleting " + Alias); - new cms.businesslogic.Dictionary.DictionaryItem(ParentID).delete(); + LogHelper.Debug(TypeID + " " + ParentID + " deleting " + Alias); + var di = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemById(ParentID); + if (di == null) return true; + + ApplicationContext.Current.Services.LocalizationService.Delete(di); return true; } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/editPackage.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/editPackage.aspx.cs index 8e69677e5b..5bc6784c86 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/editPackage.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/editPackage.aspx.cs @@ -1,6 +1,7 @@ using Umbraco.Core.Services; using System; using System.Collections.Generic; +using System.Linq; using System.Web.UI; using System.Web.UI.WebControls; @@ -148,17 +149,18 @@ namespace umbraco.presentation.developer.packages } /*Dictionary Items*/ - Dictionary.DictionaryItem[] umbDictionary = Dictionary.getTopMostItems; - foreach (Dictionary.DictionaryItem d in umbDictionary) + var umbDictionary = Services.LocalizationService.GetRootDictionaryItems(); + foreach (var d in umbDictionary) { - string liName = d.key; - if (d.hasChildren) + string liName = d.ItemKey; + var children = Services.LocalizationService.GetDictionaryItemChildren(d.Key); + if (children.Any()) liName += " (Including all child items)"; - ListItem li = new ListItem(liName, d.id.ToString()); + var li = new ListItem(liName, d.Id.ToString()); - if (pack.DictionaryItems.Contains(d.id.ToString())) + if (pack.DictionaryItems.Contains(d.Id.ToString())) li.Selected = true; dictionary.Items.Add(li); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installedPackage.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installedPackage.aspx.cs index 7b20ee25c2..6d81ea9f28 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installedPackage.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installedPackage.aspx.cs @@ -175,9 +175,10 @@ namespace umbraco.presentation.developer.packages { try { - var di = new cms.businesslogic.Dictionary.DictionaryItem(tId); + var di = Services.LocalizationService.GetDictionaryItemById(tId); + if (di == null) continue; - var li = new ListItem(di.key, di.id.ToString()); + var li = new ListItem(di.ItemKey, di.Id.ToString()); li.Selected = true; dictionaryItems.Items.Add(li); @@ -464,8 +465,11 @@ namespace umbraco.presentation.developer.packages if (int.TryParse(li.Value, out nId)) { - var di = new cms.businesslogic.Dictionary.DictionaryItem(nId); - di.delete(); + var di = Services.LocalizationService.GetDictionaryItemById(nId); + if (di != null) + { + Services.LocalizationService.Delete(di); + } _pack.Data.DictionaryItems.Remove(nId.ToString()); } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/DictionaryItemList.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/settings/DictionaryItemList.aspx.cs index 027ed98024..afb0820b71 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/DictionaryItemList.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/settings/DictionaryItemList.aspx.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Linq; using umbraco.cms.businesslogic; using Umbraco.Core; +using Umbraco.Core.Models; namespace umbraco.presentation.settings { @@ -10,7 +12,7 @@ namespace umbraco.presentation.settings { private readonly cms.businesslogic.language.Language[] _languages = cms.businesslogic.language.Language.getAll; - private readonly cms.businesslogic.Dictionary.DictionaryItem[] _topItems = Dictionary.getTopMostItems; + protected void Page_Load(object sender, EventArgs e) { @@ -25,22 +27,25 @@ namespace umbraco.presentation.settings { lt_table.Text += ""; - ProcessKeys(_topItems, 0); + ProcessKeys(Services.LocalizationService.GetRootDictionaryItems(), 0); lt_table.Text += ""; } - private void ProcessKeys(IEnumerable items, int level) { + private void ProcessKeys(IEnumerable dictionaryItems, int level) { string style = "style='padding-left: " + level * 10 + "px;'"; - foreach (Dictionary.DictionaryItem di in items) { - lt_table.Text += "" + di.key + ""; - foreach (cms.businesslogic.language.Language lang in _languages) { + foreach (var di in dictionaryItems) { + lt_table.Text += "" + di.ItemKey + ""; + + foreach (var lang in _languages) { lt_table.Text += ""; - if (string.IsNullOrEmpty(di.Value(lang.id))) + var trans = di.Translations.FirstOrDefault(x => x.LanguageId == lang.id); + + if (trans == null || string.IsNullOrEmpty(trans.Value)) lt_table.Text += ""; else lt_table.Text += ""; @@ -49,8 +54,9 @@ namespace umbraco.presentation.settings { } lt_table.Text += ""; - if (di.hasChildren) - ProcessKeys(di.Children, (level+1)); + var children = Services.LocalizationService.GetDictionaryItemChildren(di.Key); + if (children.Any()) + ProcessKeys(children, (level+1)); } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.cs index 2d63a6593b..affa0451aa 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.cs @@ -1,8 +1,10 @@ using System; +using System.Linq; using System.Web.UI; using System.Web.UI.WebControls; using umbraco.cms.presentation.Trees; using Umbraco.Core; +using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Web; using Umbraco.Web.UI; @@ -19,15 +21,15 @@ namespace umbraco.settings protected LiteralControl keyTxt = new LiteralControl(); protected uicontrols.TabView tbv = new uicontrols.TabView(); private System.Collections.ArrayList languageFields = new System.Collections.ArrayList(); - private cms.businesslogic.Dictionary.DictionaryItem currentItem; + private IDictionaryItem currentItem; protected void Page_Load(object sender, System.EventArgs e) { - currentItem = new cms.businesslogic.Dictionary.DictionaryItem(int.Parse(Request.QueryString["id"])); + currentItem = Services.LocalizationService.GetDictionaryItemById(int.Parse(Request.QueryString["id"])); // Put user code to initialize the page here Panel1.hasMenu = true; - Panel1.Text = Services.TextService.Localize("editdictionary") + ": " + currentItem.key; + Panel1.Text = Services.TextService.Localize("editdictionary") + ": " + currentItem.ItemKey; uicontrols.Pane p = new uicontrols.Pane(); @@ -39,7 +41,7 @@ namespace umbraco.settings save.ButtonType = uicontrols.MenuButtonType.Primary; Literal txt = new Literal(); - txt.Text = "

" + Services.TextService.Localize("dictionaryItem/description", new[] { currentItem.key }) + "


"; + txt.Text = "

" + Services.TextService.Localize("dictionaryItem/description", new[] { currentItem.ItemKey }) + "


"; p.addProperty(txt); foreach (cms.businesslogic.language.Language l in cms.businesslogic.language.Language.getAll) @@ -50,8 +52,10 @@ namespace umbraco.settings languageBox.ID = l.id.ToString(); languageBox.CssClass = "umbEditorTextFieldMultiple"; - if (!IsPostBack) - languageBox.Text = currentItem.Value(l.id); + if (!IsPostBack) + { + languageBox.Text = currentItem.GetTranslatedValue(l.id); + } languageFields.Add(languageBox); p.addProperty(l.FriendlyName, languageBox); @@ -70,10 +74,10 @@ namespace umbraco.settings Panel1.Controls.Add(p); } - private string BuildPath(cms.businesslogic.Dictionary.DictionaryItem current) + private string BuildPath(IDictionaryItem current) { - var parentPath = current.IsTopMostItem() ? "" : BuildPath(current.Parent) + ","; - return parentPath + current.id; + var parentPath = current.ParentId.HasValue == false ? "" : BuildPath(current) + ","; + return parentPath + current.Id; } void save_Click(object sender, EventArgs e) @@ -82,10 +86,16 @@ namespace umbraco.settings { //check for null but allow empty string! // http://issues.umbraco.org/issue/U4-1931 - if (t.Text != null) - { - currentItem.setValue(int.Parse(t.ID),t.Text); - } + if (t.Text != null) + { + Services.LocalizationService.AddOrUpdateDictionaryValue( + currentItem, + Services.LocalizationService.GetLanguageById(int.Parse(t.ID)), + t.Text); + + Services.LocalizationService.Save(currentItem); + + } } ClientTools.ShowSpeechBubble(SpeechBubbleIcon.Save, Services.TextService.Localize("speechBubbles/dictionaryItemSaved"), ""); } diff --git a/src/umbraco.cms/businesslogic/ContentType.cs b/src/umbraco.cms/businesslogic/ContentType.cs index 05df73b1b5..52955089f3 100644 --- a/src/umbraco.cms/businesslogic/ContentType.cs +++ b/src/umbraco.cms/businesslogic/ContentType.cs @@ -416,11 +416,10 @@ namespace umbraco.cms.businesslogic var lang = Language.GetByCultureCode(Thread.CurrentThread.CurrentCulture.Name); if (lang != null) { - if (Dictionary.DictionaryItem.hasKey(_description.Substring(1, _description.Length - 1))) + if (ApplicationContext.Current.Services.LocalizationService.DictionaryItemExists(_description.Substring(1, _description.Length - 1))) { - var di = - new Dictionary.DictionaryItem(_description.Substring(1, _description.Length - 1)); - return di.Value(lang.id); + var di = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemByKey(_description.Substring(1, _description.Length - 1)); + return di.GetTranslatedValue(lang.id); } } @@ -495,10 +494,11 @@ namespace umbraco.cms.businesslogic var lang = Language.GetByCultureCode(Thread.CurrentThread.CurrentCulture.Name); if (lang != null) { - if (Dictionary.DictionaryItem.hasKey(tempText.Substring(1, tempText.Length - 1))) + + if (ApplicationContext.Current.Services.LocalizationService.DictionaryItemExists(tempText.Substring(1, tempText.Length - 1))) { - var di = new Dictionary.DictionaryItem(tempText.Substring(1, tempText.Length - 1)); - return di.Value(lang.id); + var di = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemByKey(tempText.Substring(1, tempText.Length - 1)); + return di.GetTranslatedValue(lang.id); } } @@ -1468,7 +1468,11 @@ namespace umbraco.cms.businesslogic var lang = Language.GetByCultureCode(Thread.CurrentThread.CurrentCulture.Name); if (lang != null) { - return new Dictionary.DictionaryItem(tempCaption.Substring(1, tempCaption.Length - 1)).Value(lang.id); + if (ApplicationContext.Current.Services.LocalizationService.DictionaryItemExists(tempCaption.Substring(1, tempCaption.Length - 1))) + { + var di = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemByKey(tempCaption.Substring(1, tempCaption.Length - 1)); + return di.GetTranslatedValue(lang.id); + } } return "[" + tempCaption + "]"; } @@ -1625,10 +1629,10 @@ namespace umbraco.cms.businesslogic var lang = Language.GetByCultureCode(Thread.CurrentThread.CurrentCulture.Name); if (lang != null) { - if (Dictionary.DictionaryItem.hasKey(_caption.Substring(1, _caption.Length - 1))) + if (ApplicationContext.Current.Services.LocalizationService.DictionaryItemExists(_caption.Substring(1, _caption.Length - 1))) { - var di = new Dictionary.DictionaryItem(_caption.Substring(1, _caption.Length - 1)); - return di.Value(lang.id); + var di = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemByKey(_caption.Substring(1, _caption.Length - 1)); + return di.GetTranslatedValue(lang.id); } } diff --git a/src/umbraco.cms/businesslogic/Dictionary.cs b/src/umbraco.cms/businesslogic/Dictionary.cs deleted file mode 100644 index f043ddca80..0000000000 --- a/src/umbraco.cms/businesslogic/Dictionary.cs +++ /dev/null @@ -1,395 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Concurrent; -using System.ComponentModel; -using System.Data; -using System.Globalization; -using System.Threading; -using System.Xml; -using System.Linq; -using Umbraco.Core; -using umbraco.cms.businesslogic.language; -using Umbraco.Core.Models; -using Umbraco.Core.Services; -using umbraco.DataLayer; -using umbraco.BusinessLogic; -using System.Runtime.CompilerServices; -using Umbraco.Core.Xml; -using Language = umbraco.cms.businesslogic.language.Language; - -namespace umbraco.cms.businesslogic -{ - [Obsolete("Obsolete, Umbraco.Core.Services.ILocalizationService")] - public class Dictionary - { - private static readonly Guid TopLevelParent = new Guid(Constants.Conventions.Localization.DictionaryItemRootId); - - [Obsolete("Obsolete, For querying the database use the new UmbracoDatabase object ApplicationContext.Current.DatabaseContext.Database")] - protected static ISqlHelper SqlHelper - { - get { return LegacySqlHelper.SqlHelper; } - } - - /// - /// Retrieve a list of toplevel DictionaryItems - /// - public static DictionaryItem[] getTopMostItems - { - get - { - return ApplicationContext.Current.Services.LocalizationService.GetRootDictionaryItems() - .Select(x => new DictionaryItem(x)) - .ToArray(); - } - } - - /// - /// A DictionaryItem is basically a key/value pair (key/language key/value) which holds the data - /// associated to a key in various language translations - /// - public class DictionaryItem - { - public DictionaryItem() - { - - } - - internal DictionaryItem(IDictionaryItem item) - { - _dictionaryItem = item; - } - - private readonly IDictionaryItem _dictionaryItem; - private DictionaryItem _parent; - - public DictionaryItem(string key) - { - _dictionaryItem = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemByKey(key); - - if (_dictionaryItem == null) - { - throw new ArgumentException("No key " + key + " exists in dictionary"); - } - } - - public DictionaryItem(Guid id) - { - _dictionaryItem = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemById(id); - - if (_dictionaryItem == null) - { - throw new ArgumentException("No unique id " + id + " exists in dictionary"); - } - } - - public DictionaryItem(int id) - { - _dictionaryItem = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemById(id); - - if (_dictionaryItem == null) - { - throw new ArgumentException("No id " + id + " exists in dictionary"); - } - } - - [Obsolete("This is no longer used and will be removed from the codebase in future versions")] - public bool IsTopMostItem() - { - return _dictionaryItem.ParentId.HasValue == false; - } - - /// - /// Returns the parent. - /// - public DictionaryItem Parent - { - get - { - //EnsureCache(); - if (_parent == null && _dictionaryItem.ParentId.HasValue) - { - var p = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemById(_dictionaryItem.ParentId.Value); - - if (p == null) - { - throw new ArgumentException("Top most dictionary items doesn't have a parent"); - } - else - { - _parent = new DictionaryItem(p); - } - } - - return _parent; - } - } - - /// - /// The primary key in the database - /// - public int id - { - get { return _dictionaryItem.Id; } - } - - public DictionaryItem[] Children - { - get - { - return ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemChildren(_dictionaryItem.Key) - .WhereNotNull() - .Select(x => new DictionaryItem(x)) - .ToArray(); - } - } - - public static bool hasKey(string key) - { - return ApplicationContext.Current.Services.LocalizationService.DictionaryItemExists(key); - } - - public bool hasChildren - { - get { return Children.Any(); } - } - - /// - /// Returns or sets the key. - /// - public string key - { - get { return _dictionaryItem.ItemKey; } - set - { - if (hasKey(value) == false) - { - _dictionaryItem.ItemKey = value; - } - else - throw new ArgumentException("New value of key already exists (is key)"); - } - } - - public string Value(int languageId) - { - if (languageId == 0) - return Value(); - - var translation = _dictionaryItem.Translations.FirstOrDefault(x => x.Language.Id == languageId); - return translation == null ? string.Empty : translation.Value; - } - - public void setValue(int languageId, string value) - { - ApplicationContext.Current.Services.LocalizationService.AddOrUpdateDictionaryValue( - _dictionaryItem, - ApplicationContext.Current.Services.LocalizationService.GetLanguageById(languageId), - value); - - Save(); - } - - /// - /// Returns the default value based on the default language for this item - /// - /// - public string Value() - { - var defaultTranslation = _dictionaryItem.Translations.FirstOrDefault(x => x.Language.Id == 1); - return defaultTranslation == null ? string.Empty : defaultTranslation.Value; - } - - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This is not used and should never be used, it will be removed from the codebase in future versions")] - public void setValue(string value) - { - if (Item.hasText(_dictionaryItem.Key, 0)) - Item.setText(0, _dictionaryItem.Key, value); - else - Item.addText(0, _dictionaryItem.Key, value); - - Save(); - } - - public static int addKey(string key, string defaultValue, string parentKey) - { - //EnsureCache(); - - if (hasKey(parentKey)) - { - int retval = CreateKey(key, new DictionaryItem(parentKey)._dictionaryItem.Key, defaultValue); - return retval; - } - else - throw new ArgumentException("Parentkey doesnt exist"); - } - - public static int addKey(string key, string defaultValue) - { - int retval = CreateKey(key, TopLevelParent, defaultValue); - return retval; - } - - public void delete() - { - OnDeleting(EventArgs.Empty); - - ApplicationContext.Current.Services.LocalizationService.Delete(_dictionaryItem); - - OnDeleted(EventArgs.Empty); - } - - /// - /// ensures events fire after setting proeprties - /// - public void Save() - { - OnSaving(EventArgs.Empty); - - ApplicationContext.Current.Services.LocalizationService.Save(_dictionaryItem); - } - - - public XmlNode ToXml(XmlDocument xd) - { - var serializer = new EntityXmlSerializer(); - var xml = serializer.Serialize(_dictionaryItem); - var xmlNode = xml.GetXmlNode(xd); - if (this.hasChildren) - { - foreach (var di in this.Children) - { - xmlNode.AppendChild(di.ToXml(xd)); - } - } - return xmlNode; - } - - public static DictionaryItem Import(XmlNode xmlData) - { - return Import(xmlData, null); - } - - public static DictionaryItem Import(XmlNode xmlData, DictionaryItem parent) - { - string key = xmlData.Attributes["Key"].Value; - - XmlNodeList values = xmlData.SelectNodes("./Value"); - XmlNodeList childItems = xmlData.SelectNodes("./DictionaryItem"); - DictionaryItem newItem; - bool retVal = false; - - if (!hasKey(key)) - { - if (parent != null) - addKey(key, " ", parent.key); - else - addKey(key, " "); - - if (values.Count > 0) - { - //Set language values on the dictionary item - newItem = new DictionaryItem(key); - foreach (XmlNode xn in values) - { - string cA = xn.Attributes["LanguageCultureAlias"].Value; - string keyValue = XmlHelper.GetNodeValue(xn); - - Language valueLang = Language.GetByCultureCode(cA); - - if (valueLang != null) - { - newItem.setValue(valueLang.id, keyValue); - } - } - } - - if (parent == null) - retVal = true; - } - - newItem = new DictionaryItem(key); - - foreach (XmlNode childItem in childItems) - { - Import(childItem, newItem); - } - - if (retVal) - return newItem; - else - return null; - } - - private static int CreateKey(string key, Guid parentId, string defaultValue) - { - if (!hasKey(key)) - { - var item = ApplicationContext.Current.Services.LocalizationService.CreateDictionaryItemWithIdentity( - key, - parentId == TopLevelParent ? (Guid?)null : parentId, - defaultValue); - - return item.Id; - } - else - { - throw new ArgumentException("Key being added already exists!"); - } - } - - #region Events - public delegate void SaveEventHandler(DictionaryItem sender, EventArgs e); - public delegate void NewEventHandler(DictionaryItem sender, EventArgs e); - public delegate void DeleteEventHandler(DictionaryItem sender, EventArgs e); - - public static event SaveEventHandler Saving; - protected virtual void OnSaving(EventArgs e) - { - if (Saving != null) - Saving(this, e); - } - - public static event NewEventHandler New; - protected virtual void OnNew(EventArgs e) - { - if (New != null) - New(this, e); - } - - public static event DeleteEventHandler Deleting; - protected virtual void OnDeleting(EventArgs e) - { - if (Deleting != null) - Deleting(this, e); - } - - public static event DeleteEventHandler Deleted; - protected virtual void OnDeleted(EventArgs e) - { - if (Deleted != null) - Deleted(this, e); - } - #endregion - } - - // zb023 - utility method - public static string ReplaceKey(string text) - { - if (text.StartsWith("#") == false) - return text; - - var lang = Language.GetByCultureCode(Thread.CurrentThread.CurrentCulture.Name); - - if (lang == null) - return "[" + text + "]"; - - if (DictionaryItem.hasKey(text.Substring(1, text.Length - 1)) == false) - return "[" + text + "]"; - - var di = new DictionaryItem(text.Substring(1, text.Length - 1)); - return di.Value(lang.id); - } - - } -} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/Packager/PackageInstance/CreatedPackage.cs b/src/umbraco.cms/businesslogic/Packager/PackageInstance/CreatedPackage.cs index 32c406d100..b757e60dc3 100644 --- a/src/umbraco.cms/businesslogic/Packager/PackageInstance/CreatedPackage.cs +++ b/src/umbraco.cms/businesslogic/Packager/PackageInstance/CreatedPackage.cs @@ -250,8 +250,10 @@ namespace umbraco.cms.businesslogic.packager { if (int.TryParse(dictionaryId, out outInt)) { - var di = new Dictionary.DictionaryItem(outInt); - dictionaryItems.AppendChild(di.ToXml(_packageManifest)); + var di = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemById(outInt); + var entitySerializer = new EntityXmlSerializer(); + var xmlNode = entitySerializer.Serialize(di).GetXmlNode(_packageManifest); + dictionaryItems.AppendChild(xmlNode); } } AppendElement(dictionaryItems); diff --git a/src/umbraco.cms/businesslogic/propertytype/propertytype.cs b/src/umbraco.cms/businesslogic/propertytype/propertytype.cs index b9d8d20a44..613a374f00 100644 --- a/src/umbraco.cms/businesslogic/propertytype/propertytype.cs +++ b/src/umbraco.cms/businesslogic/propertytype/propertytype.cs @@ -156,11 +156,11 @@ namespace umbraco.cms.businesslogic.propertytype Language lang = Language.GetByCultureCode(Thread.CurrentThread.CurrentCulture.Name); if (lang != null) { - if (Dictionary.DictionaryItem.hasKey(_description.Substring(1, _description.Length - 1))) + + if (ApplicationContext.Current.Services.LocalizationService.DictionaryItemExists(_description.Substring(1, _description.Length - 1))) { - var di = - new Dictionary.DictionaryItem(_description.Substring(1, _description.Length - 1)); - return di.Value(lang.id); + var di = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemByKey(_description.Substring(1, _description.Length - 1)); + return di.GetTranslatedValue(lang.id); } } } @@ -224,10 +224,11 @@ namespace umbraco.cms.businesslogic.propertytype Language lang = Language.GetByCultureCode(Thread.CurrentThread.CurrentCulture.Name); if (lang != null) { - if (Dictionary.DictionaryItem.hasKey(_name.Substring(1, _name.Length - 1))) + + if (ApplicationContext.Current.Services.LocalizationService.DictionaryItemExists(_name.Substring(1, _name.Length - 1))) { - var di = new Dictionary.DictionaryItem(_name.Substring(1, _name.Length - 1)); - return di.Value(lang.id); + var di = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemByKey(_name.Substring(1, _name.Length - 1)); + return di.GetTranslatedValue(lang.id); } } diff --git a/src/umbraco.cms/businesslogic/template/Template.cs b/src/umbraco.cms/businesslogic/template/Template.cs index e45fdec3cb..aca2b5ce9b 100644 --- a/src/umbraco.cms/businesslogic/template/Template.cs +++ b/src/umbraco.cms/businesslogic/template/Template.cs @@ -88,12 +88,11 @@ namespace umbraco.cms.businesslogic.template { language.Language lang = language.Language.GetByCultureCode(System.Threading.Thread.CurrentThread.CurrentCulture.Name); if (lang != null) - { - if (Dictionary.DictionaryItem.hasKey(tempText.Substring(1, tempText.Length - 1))) + { + if (ApplicationContext.Current.Services.LocalizationService.DictionaryItemExists(tempText.Substring(1, tempText.Length - 1))) { - Dictionary.DictionaryItem di = new Dictionary.DictionaryItem(tempText.Substring(1, tempText.Length - 1)); - if (di != null) - return di.Value(lang.id); + var di = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemByKey(tempText.Substring(1, tempText.Length - 1)); + return di.GetTranslatedValue(lang.id); } } diff --git a/src/umbraco.cms/umbraco.cms.csproj b/src/umbraco.cms/umbraco.cms.csproj index b5ff0e5430..02f44ab9d4 100644 --- a/src/umbraco.cms/umbraco.cms.csproj +++ b/src/umbraco.cms/umbraco.cms.csproj @@ -194,9 +194,6 @@ Code - - Code - Code