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 开发者_C百科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.
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.
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.
精彩评论