How can I get the system language in C/C++?

2019-05-07 17:53发布

问题:

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

回答1:

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



回答2:

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).



回答3:

Dup of Find out the language windows was installed as

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



回答4:

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.



标签: c++ c posix locale