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
精彩评论