How to get windows system locale?

Hi,
Please tell me how to get system locale, I wnat directly got string like "en-US", "jp", "zh-TW", this kind of locale format, please tell me how to do this, Thanks!
rocktilldieAsked:
Who is Participating?
 
LudvikJerabekCommented:
This should give you exactly what you are looking for en-US  ... ect

#include <windows.h>
#include <tchar.h>

void _tmain()
{
   TCHAR lang[16] = {0};
   TCHAR ctry[16] = {0};
   TCHAR code[33] = {0};
   ::GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SISO639LANGNAME ,lang,sizeof(lang));
   ::GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SISO3166CTRYNAME,ctry,sizeof(ctry));
   _tcscat( code , lang );
   _tcscat( code , _T("-"));
   _tcscat( code , ctry );
   ::MessageBox( NULL , code , _T("Locale") , MB_OK );
}      
0
 
jkrCommented:
Call 'GetSystemDefaultLCID()' (http://msdn2.microsoft.com/en-us/library/ms776315.aspx) when you are on Windows, for UN*X-like systems, use

#include <locale.h>
char* myLocale = setlocale(LC_ALL,NULL);

(the latter will work on Windows also)
0
 
jkrCommented:
Oh, BTW, to get the strings you mentioned above, there's 'GetLocaleInfo()' (http://msdn2.microsoft.com/en-us/library/ms776270.aspx), so you'd

char scLocale[16];
LCID lcid = GetSystemDefaultLCID();

GetLocaleInfo(lcid,LOCALE_SLANGDISPLAYNAME,acLocale,sizeof(acLocale));

or

GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SLANGDISPLAYNAME,acLocale,sizeof(acLocale));
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.