How can I ensure that the appropriate language version of a string resource is loaded at runtime?

256 views Asked by At

I have a string resource file called "strings.resx" in my VB.NET project, defined as an embedded resource. I have another file called strings.es.resx, which contains all of the same strings in Spanish. I'm loading the resource at runtime using the following code:

MyStrings = New ResourceManager("myprog.strings", GetType(MainForm).Assembly)

I've set the language locale to Espanol in Windows and logged back in, but I'm still getting the English string resources loading when the above is executed. How can I load the spanish resources if the Windows locale is ES? I was expecting it to be handled automatically.

2

There are 2 answers

4
Andras Zoltan On BEST ANSWER

Take a look at the System.Threading.Thread.CurrentThread.CurrentUICulture property - it has a habit of being fixed to en-US.

If it is, try setting it to the same as CurrentCulture.

Update

Since that didn't work, check that the the output folder of your application has an es folder, inside which is a dll called strings.resources.dll. If not, then, basically, the resource manager is not finding the culture-specific string resource, because it's not there, in which case copy them in and it should work.

1
Christian Hayter On

DISCLAIMER - this is all from memory and may not be 100% accurate :-)

.NET resources are loaded using Thread.CurrentUICulture (unless you explicitly override it when loading resources in code). Thread.CurrentUICulture is set by the UI language used in your installation of Windows, and cannot be changed. This is not the same as Thread.CurrentCulture, which is set in Control Panel, and can be changed at any time.

For example, on my PC, CurrentCulture returns "en-GB" because that's where I am, but CurrentUICulture returns "en-US" because Microsoft only provide one English language version of Windows.