开发者

Getting a string from a resource file in an untyped manner

开发者 https://www.devze.com 2023-01-28 08:28 出处:网络
I\'m working on an ASP.Net project which has all of its translations in a T开发者_Python百科ranslations.resx file. Is there an easy way to get a translated string in an untyped manner?

I'm working on an ASP.Net project which has all of its translations in a T开发者_Python百科ranslations.resx file. Is there an easy way to get a translated string in an untyped manner?

I don't want to do

Translations.TranslateThisKey

but rather something like

Translations["TranslateThisKey"]

I need this because the key is a code coming from an external resource.


try this

var Translations = new ResourceManager("MyResources", 
    Assembly.GetExecutingAssembly())
        .GetResourceSet(CultureInfo.CurrentCulture, false, true)
        .Cast<DictionaryEntry>()
        .Where(e => e.Value is string)
        .ToDictionary(e => e.Key, e => (string) e.Value);

var result = Translations["TranslateThisKey"];


Resources.ResourceManager.GetString("NAME_OF_YOUR_STRING_IN_RESX_FILE")


I think what you need is a ResourceManager

0

精彩评论

暂无评论...
验证码 换一张
取 消