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?
You can manually change the
Cultureproperty of the FooBar class that Visual Studio generates. Or if you are directly using the ResourceManager class, you can use the overload of GetString that takes the desired culture as a parameter.