Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Created May 30, 2015 21:11
Show Gist options
  • Save netsi1964/97b80d3a876696935049 to your computer and use it in GitHub Desktop.
Save netsi1964/97b80d3a876696935049 to your computer and use it in GitHub Desktop.
Umbraco usefull global translate function
@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