Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: How to get a resource string from a certain culture

Tags:

I have a resource assembly with translated texts in various languages. Project kind of looks like this:

  • FooBar.resx
  • FooBar.nb-NO.resx
  • FooBar.sv-SE.resx
  • ...

I can get the texts using static properties like this:

var value = FooBar.Hello; 

Or by using reflection like this:

var value = resourceAssembly       .GetType("Namespace.FooBar")       .GetProperty("Hello")       .GetValue(null, null) as string; 

Both ways will get me the value belonging to the current UI culture of the current thread. Which is fine and totally what I would usually like.

But, is there something I can do if I explicitly want for example the Swedish value, without having to change the UI culture?

like image 629
Svish Avatar asked Dec 01 '09 11:12

Svish


1 Answers

Try the following code. It worked fine for me at least:

FooBar.ResourceManager.GetString("Hello", CultureInfo.GetCultureInfo("sv-SE")) 
like image 106
Himanshu Vohra Avatar answered Sep 23 '22 21:09

Himanshu Vohra