Factor Dictionary.ReplaceKey method

This commit is contained in:
Stephan
2014-01-26 14:59:35 +01:00
parent cec4d41df7
commit 3b6dcc3421
2 changed files with 21 additions and 23 deletions

View File

@@ -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);
}
}
}

View File

@@ -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<int, String> 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 + "]";
}
}
}
}