문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top