views:

199

answers:

5

How can I get the system language in C/C++? Like en_US or en_GB.

+3  A: 

Dup of http://stackoverflow.com/questions/953416/find-out-the-language-windows-was-installed-as

In summary - "the Win32 function you want is GetSystemDefaultUILanguage()" (assuming Windows of course)

Steve Townsend
OP doesn't say specifically Windows.
Zack
Actually, now he says Linux. Thankfully I don't have enough karma to officially dup posts.
Steve Townsend
+1 even if OP commented about POSIX, it might be useful to others finding the question through Google
Vincent Robert
+5  A: 

On a POSIX system, it looks like setlocale(LC_CTYPE, NULL); would return the current locale.

Mike G.
setlocale(LC_CTYPE, "") worked, thanks!
Jookia
@Jookia: that also changes the locale to the user-specified locale (as determined by the environment).
R..
+2  A: 

C++, as a language has no such facilities.

It's OS dependant.

Edit:

Sorry... I wasn't aware of std::locale. It is good to learn new things.

Lior Kogan
+4  A: 

Generally you don't -- rather, you (usually) want to just conform to what it asks for using the nameless locale (i.e., std::locale(""); will give you the locale of the user's choosing).

Jerry Coffin
A: 

There isn't necessarily one system language; individual "facets" of the locale can be configured separately. It's all done with environment variables; http://www.manpagez.com/man/1/locale/ has a partial list of variables and their meanings.

Zack