2010-12-06 43 views
0

我正在研究一個ASP.Net項目,該項目的所有翻譯都在Translations.resx文件中。有沒有一種簡單的方法來獲得一個非類型化的翻譯字符串?以非類型化的方式從資源文件中獲取字符串

我不想做

Translations.TranslateThisKey 

而是像

Translations["TranslateThisKey"] 

我需要這個,因爲關鍵是要從外部資源來代碼。

回答

2

試試這個

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"]; 
1
Resources.ResourceManager.GetString("NAME_OF_YOUR_STRING_IN_RESX_FILE") 
相關問題