
Question:
I have an application, which works with Resources for translation. This is working great. Now, I have a special requirement. For this, I have to load the resource-dll for another language (for example, the application starts and works with English, then I have to also to load the German-translations) and look into it for a translation.
Is there an easy-way to do this?
Answer1:You need to load the resourcemanager and If you need the resources for an specific language you will need to ask for them using the specific culture, using:
GetObject(String, CultureInfo)
You can create the culture that you need using:
new CultureInfo(string name)
Or
CultureInfo.CreateSpecificCulture(string name)
Or
CultureInfo.GetCultureInfo(string name)
The name is the culture name: "en" English, "de" German... You can see a full list on the following link: <a href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo%28VS.71%29.aspx" rel="nofollow">cultures</a>
Answer2:
using System.Resources;
using System.Reflection;
Assembly gerResAssembly = Assembly.LoadFrom("YourGerResourceAssembly.dll");
var resMgr = new ResourceManager("StringResources.Strings", gerResAssembly);
string gerString = resMgr.GetString("TheNameOfTheString");
Answer3:You can make it, with the <a href="http://msdn.microsoft.com/en-us/library/bsb0cfet%28v=vs.110%29.aspx" rel="nofollow">GetString</a> calling the together with the specific <a href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo%28v=vs.110%29.aspx" rel="nofollow">CultureInfo</a> you need. for example:
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"));
`