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