Loading resources for another language

I have an application that works with translation resources. This works great. Now I have a special requirement. To do this, I need to download the dll resource for another language (for example, the application starts and works with English, then I also need to download German translations) and look at it for translation.

Is there an easy way to do this?

+3
source share
3 answers

You need to download the resource manager, and if you need resources for a specific language, you will need to ask them to use a specific culture using:

GetObject(String, CultureInfo)

You can create the culture you need:

new CultureInfo(string name)

or

CultureInfo.CreateSpecificCulture(string name)

or

CultureInfo.GetCultureInfo(string name)

- : "en" English, "de" German... : culture

+3
using System.Resources;
using System.Reflection;

Assembly gerResAssembly = Assembly.LoadFrom("YourGerResourceAssembly.dll");
var resMgr = new ResourceManager("StringResources.Strings", gerResAssembly);
string gerString = resMgr.GetString("TheNameOfTheString");
+1

You can do this using GetString calling along with the specific CultureInfo you need. eg:

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"));

`

+1
source

Source: https://habr.com/ru/post/1787305/


All Articles