我有一個應用程序,它可以與資源進行翻譯。這很好。 現在,我有一個特殊的要求。爲此,我必須加載另一種語言的資源dll(例如,應用程序啓動並使用英語,然後我還必須加載德語翻譯)並查看它以進行翻譯。爲其他語言加載資源
有沒有簡單的方法來做到這一點?
我有一個應用程序,它可以與資源進行翻譯。這很好。 現在,我有一個特殊的要求。爲此,我必須加載另一種語言的資源dll(例如,應用程序啓動並使用英語,然後我還必須加載德語翻譯)並查看它以進行翻譯。爲其他語言加載資源
有沒有簡單的方法來做到這一點?
你需要加載的ResourceManager,如果你需要的資源爲特定的語言,你需要使用特定的文化,要求他們使用:
GetObject(String, CultureInfo)
您可以創建文化你需要使用:
new CultureInfo(string name)
或者
CultureInfo.CreateSpecificCulture(string name)
或者
CultureInfo.GetCultureInfo(string name)
名稱是區域性名稱:「恩」英語,「德」德國...你可以看到下面的鏈接的完整列表:cultures
using System.Resources;
using System.Reflection;
Assembly gerResAssembly = Assembly.LoadFrom("YourGerResourceAssembly.dll");
var resMgr = new ResourceManager("StringResources.Strings", gerResAssembly);
string gerString = resMgr.GetString("TheNameOfTheString");
你可以把它,與GetString 一起調用您需要的具體CultureInfo。 例如:
using System.Resources;
using System.Reflection;
Assembly gerResAssembly = Assembly.LoadFrom("YourGerResourceAssembly.dll");
var resMgr = new ResourceManager("StringResources.Strings", gerResAssembly);
// for example german:
string strDE = resMgr.GetString("TheNameOfTheString", new CultureInfo("de"));
// for example spanish
string strES = resMgr.GetString("TheNameOfTheString", new CultureInfo("es"));
`