Which language strings to load? How to load them?

by Michael S. Kaplan, published on 2006/05/13 13:15 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/05/13/596971.aspx

The SZ (a.k.a. Steffen) asked in the suggestion box:

What is the prefered way to select the "most usefull" language in a multi language app?

If I'm using "LoadString" I'm getting the os language
If I'm using "GetUserDefaultUILanguage" I'm getting the os language if no mui pack is installed.

I know there are are a lot of posts about the trillions of different language api's. I know windows doesn't have a "I wanna that the apps are talking 'german'" setting. But a german user on a english os will set something or all possible settings in the control panel to something german.

Currently I'm using GetUserDefaultLangID.


Actually, the LoadString function is a simple wrapper around FindResource, which uses the user UI language provided by GetUserDefaultUILanguage. Before the Multilingual User Interface existed, this was always the OS install language, but now it is completely configurable to whatever language th operating system is set to.

While it makes a good default (there is an obvious good faith basis that a developer can assume that a user knows the language into which the OS is translated, at least well enough to navigate to an installed application!), it is always possible that an application might be translated into more languages than are actually available in the UI language list.

In such cases, an application might still wish to use the UI language provided by GetUserDefaultUILanguage as a starting point, it may make sense to provide a custom user interface to allow language selection that diverges from the operating system list....

Of course, going down the FindResourceEx/LoadResource/LockResource route starts off easily enough but gets more complicated after that, which is one of the reasons that LoadString is so appealing as a function, and why a LoadStringEx that takes a language would really be a sensible addition to the platform.

The format of string resources is described in the MS Knowledge Base (196774) and Raymond Chen posted a good sample on how to actually use this knowledge in his post The Format of String Resources. It saves me from posting such a function here, so I will just go ahead and riff on Raymond a bit. :-)

You can also look to him for an explanation of why UnlockResource and FreeResource are no longer needed in his post The management of memory for resources in 16-bit Windows.

In truth, all that LockResource currently does in a cast from an HGLOBAL to an LPVOID (as others have noticed, they both seem to have the same pointer), but this is a time when it is best to take as hint from the documentation and keep calling it, in case that ever changes....


This post brought to you by "ઍ" (U+0a8d, a.k.a. GUJARATI VOWEL CANDRA E)

# Mihai on 13 May 2006 4:37 PM:

<<going down the FindResourceEx/LoadResource/LockResource route starts off easily enough but gets more complicated>>

This is one of the reasons why resource only DLLs with one language per DLL is better.

# Michael S. Kaplan on 13 May 2006 4:42 PM:

Very true, Mihai!

Though if you look at the Vista model, they are looking to get the best of both worlds. More on this, soon. :-)

# Mihai on 13 May 2006 5:35 PM:

<<if you look at the Vista model, they are looking to get the best of both worlds>>
I think this is rethorical :-) You know I did already :-)

But I would go beyond the technical part (API and such).
As user experience, I would prefer to allow the user to select the language per application.
So I would say the user should get a list with all languages in which the application is available (which is completely independent of the OS) plus an extra option "Match the OS UI Language"
The user can sort the list as he prefers, and this is is.

For instance:
 Match the system
will allways show French

Example 2
 Match the system
Will show French if OS UI is French
Will show English if OS UI is English
Will show Italian if OS UI is Italian
Will show French if OS UI is anything else

# Michael S. Kaplan on 13 May 2006 6:05 PM:

Well, like I said I'll be talking about the changes to the model for Vista that support this notion more fully....

Hang in there, it is coming soon!

# Dean Harding on 14 May 2006 8:42 PM:

Yeah, I remember doing the string-table parsing myself, once. It was for a server product where the client sent their language ID over a custom protocol we had. I was really wishing there was a LoadStringEx then :)

# Centaur on 15 May 2006 3:40 AM:

I absolutely hate it when applications detect that I have Russian locale set, forget to check my default UI language, and try to talk to me in Russian. Sadly, there are still many of those, and I suppose a major reason is that GetUserDefaultUILanguage did not exist before XP, and those developers cannot be bothered to write OS-specific language detection code.

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

referenced by

2007/07/13 GetLocaleInfo for other languages?

go to newer or older post, or back to index or month or day