Created
May 30, 2015 21:11
-
-
Save netsi1964/97b80d3a876696935049 to your computer and use it in GitHub Desktop.
Umbraco usefull global translate function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@functions { | |
/// <summary> | |
/// Using Dictionary return a translation or default value | |
/// If defaultValue is empty and the key was not defined, a "*"+key will be returned | |
/// So that you know that you need to create a translation/dictionary for that key | |
/// </summary> | |
/// <param name="key">The dictonary key to search for</param> | |
/// <param name="defaultValue">A optional default value</param> | |
/// <returns>The found dictonary</returns> | |
public static String Translate(string key, string defaultValue = "") | |
{ | |
Umbraco.Web.UmbracoHelper helper = new Umbraco.Web.UmbracoHelper(); | |
string value = helper.GetDictionaryValue(key); | |
defaultValue = (String.IsNullOrEmpty(defaultValue) ? "*" + key : defaultValue); | |
return (String.IsNullOrEmpty(value) ? defaultValue : value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment