Discussion:
How to detect system language ?
(too old to reply)
Kid
2010-06-18 03:06:51 UTC
Permalink
Hi

How can I detect Windows system language or codepage by Win32 or MFC ?

Is there some registry key to query ?

Thank you .
David Ching
2010-06-18 04:37:41 UTC
Permalink
Post by Kid
How can I detect Windows system language or codepage by Win32 or MFC ?
e.g.
WORD wDefLang = LANGIDFROMLCID(GetUserDefaultLCID());
LANGID wDefLang = GetSystemDefaultLangID(); // or
GetUserDefaultLangID();

There is some debate about which API is appropriate for your usage.

-- David
Mihai N.
2010-06-18 07:44:45 UTC
Permalink
Post by Kid
How can I detect Windows system language or codepage by Win32 or MFC ?
It depends what you mean by "system language"

For each you have the option to get them in a numeric form
(LCID, used all the way to XP) or string (starting with Vista)
You can also get a language ID (LANGID), but it might not be enough
for all operations (a locale is usualy a better choice).

The language in which the UI was localized at install time?
GetSystemDefaultUILanguage -> LANGID

The language in which the UI is displayed right now?
(might be different than the system UI language if you have a MUI or LIP)
GetUserDefaultUILanguage -> LANGID

The system locale (that determines the ANSI and OEM code pages)?
GetSystemDefaultLocaleName -> string
GetSystemDefaultLCID -> LCID
GetSystemDefaultLangID -> LANGID

The locale used for locale-sensitive operations
(number/currency/date/time formatting, sorting, case conversion)?
GetUserDefaultLocaleName -> string
GetUserDefaultLCID -> LCID
GetUserDefaultLangID -> LANGID


For system code page there are two of them:
- the ANSI code page => GetACP
- the OEM code page, used (by default) by console apps => GetOEMCP
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Tom Serface
2010-06-18 15:23:14 UTC
Permalink
I use pretty simple code like:

LCID lcid = ::GetThreadLocale() & 0x00ff;
lcid |= lcid == 0x0004?0x0800:0x0400; // Chinese starts with 08, but all
others 04

Then I build a filename for the language DLL using

CString csResourceDLL = GetResourceFilename(lcid, _T("MYAPP%1.dll"));

//
// Creates a resource file name (for a DLL) given the locale id and a format
string.
//
CString GetResourceFilename(UINT nLID, LPCTSTR cFormat)
{
CString csHex, cs;
csHex.Format(_T("%04x"), nLID);
cs.FormatMessage(cFormat,csHex);
return cs;
}

But we don't use the sub language since we don't support anything except a
few top level languages.

Tom
Post by Kid
Hi
How can I detect Windows system language or codepage by Win32 or MFC ?
Is there some registry key to query ?
Thank you .
Mihai N.
2010-06-20 09:30:18 UTC
Permalink
Post by Tom Serface
LCID lcid = ::GetThreadLocale() & 0x00ff;
What you need is LANGIDFROMLCID :-)
http://msdn.microsoft.com/en-us/library/dd318689%28v=VS.85%29.aspx
Post by Tom Serface
lcid |= lcid == 0x0004?0x0800:0x0400; // Chinese starts with 08, but all
others 04
...
Post by Tom Serface
But we don't use the sub language since we don't support anything except a
few top level languages.
Actually, you are trying to get the language.

For Chinese that is not enough, you have to look at the region.
That's because Chinese Traditional (usualy mapped to Chinese-Taiwan)
and Chinese Simplified (usualy mapped to Chinese-China) are not mutualy
inteligible.

It works just because you did not have to deal with other languages
that can be written with different scripts.
Examples:
- Azeri, Bosnian, Serbian, Uzbek (Cyrillic and Latin)
- Inuktitut (Latin and Inuktitut Syllabics)
- Mongolian (Cyrillic and Mongolian)
In fact, even the localizations for Portuguese Portugal and
Portuguese Brazil should be different, because they are kind of far,
even with if they use the same script.

Another problem is that language identifiers for
Bosnian, Croatian, and Serbian are numerically identical.
To differenciate between these languages you *must* look at the sublang.
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Mihai N.
2010-06-20 09:35:24 UTC
Permalink
Post by Kid
How can I detect Windows system language or codepage by Win32 or MFC ?
@All :-)

Before answering, he should make sure he knows what he wants.

In the MS lingo, "Windows system language" is the one that determines the
ANSI/OEM code pages. It is not good to decide the UI language, or to format
stuff with it in a locale-sensitive manner.
It is different than the one from GetThreadLocale or GetUserDefaultLCID.
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Continue reading on narkive:
Loading...