Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to get windows system locale?

Posted on 2007-08-09
3
Medium Priority
?
3,599 Views
Last Modified: 2013-11-05
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!
0
Comment
Question by:rocktilldie
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 19662967
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
 
LVL 86

Expert Comment

by:jkr
ID: 19663111
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
 
LVL 1

Accepted Solution

by:
LudvikJerabek earned 1500 total points
ID: 19667870
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question