From 3b6dcc3421d2fe17d2d36f146fdcb108d80e5eb0 Mon Sep 17 00:00:00 2001 From: Stephan Date: Sun, 26 Jan 2014 14:59:35 +0100 Subject: [PATCH] Factor Dictionary.ReplaceKey method --- src/umbraco.cms/businesslogic/Dictionary.cs | 19 ++++++++++++++ .../dropdownlist/dropdown.cs | 25 ++----------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/umbraco.cms/businesslogic/Dictionary.cs b/src/umbraco.cms/businesslogic/Dictionary.cs index e524f90429..cd32162fa7 100644 --- a/src/umbraco.cms/businesslogic/Dictionary.cs +++ b/src/umbraco.cms/businesslogic/Dictionary.cs @@ -532,5 +532,24 @@ namespace umbraco.cms.businesslogic } #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.editorControls/dropdownlist/dropdown.cs b/src/umbraco.editorControls/dropdownlist/dropdown.cs index f4d887cfb4..2cc44ae6a9 100644 --- a/src/umbraco.editorControls/dropdownlist/dropdown.cs +++ b/src/umbraco.editorControls/dropdownlist/dropdown.cs @@ -59,7 +59,7 @@ namespace umbraco.editorControls { foreach (object key in _prevalues.Keys) { - this.Items.Add(new ListItem(dropdown.DictionaryReplace(_prevalues[key].ToString()), key.ToString())); + this.Items.Add(new ListItem(Dictionary.ReplaceKey(_prevalues[key].ToString()), key.ToString())); } } @@ -67,7 +67,7 @@ namespace umbraco.editorControls { foreach (KeyValuePair item in Prevalues) { - this.Items.Add(new ListItem(dropdown.DictionaryReplace(item.Value), item.Key.ToString())); + this.Items.Add(new ListItem(Dictionary.ReplaceKey(item.Value), item.Key.ToString())); } } @@ -76,26 +76,5 @@ namespace umbraco.editorControls if (_data != null && _data.Value != null) this.SelectedValue = _data.Value.ToString(); } - - static string DictionaryReplace(string text) - { - if (!text.StartsWith("#")) - return text; - else - { - Language lang = Language.GetByCultureCode(System.Threading.Thread.CurrentThread.CurrentCulture.Name); - if (lang != null) - { - if (Dictionary.DictionaryItem.hasKey(text.Substring(1, text.Length - 1))) - { - Dictionary.DictionaryItem di = new Dictionary.DictionaryItem(text.Substring(1, text.Length - 1)); - return di.Value(lang.id); - } - } - - return "[" + text + "]"; - } - } - } } \ No newline at end of file