Umbraco get dictionary item by language, how?

[亡魂溺海] 提交于 2019-12-05 04:41:53

Use the LocalizationService to get the dictionary item by language. I created a static method that does this:

public static string GetDictionaryValue(string key, CultureInfo culture, UmbracoContext context)
{
    var dictionaryItem = context.Application.Services.LocalizationService.GetDictionaryItemByKey(key);
    if (dictionaryItem != null)
    {
        var translation = dictionaryItem.Translations.SingleOrDefault(x => x.Language.CultureInfo.Equals(culture));
        if (translation != null)
            return translation.Value;
    }
    return key; // if not found, return key
}

As far as I know, Umbraco does not have the static method to get dictionary item by a specific language at the moment. I must do same as you to get the dictionary item by language (I used Umbraco version 7.2.8). However, I get the language list by function that is provided by Umbraco.

I hope Umbraco will add this function in future versions. I think it is necessary as you told.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!