How to get windows system locale?

Posted on 2007-08-09
Last Modified: 2013-11-05
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!
Question by:rocktilldie
    LVL 86

    Expert Comment

    Call 'GetSystemDefaultLCID()' ( 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)
    LVL 86

    Expert Comment

    Oh, BTW, to get the strings you mentioned above, there's 'GetLocaleInfo()' (, so you'd

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



    LVL 1

    Accepted Solution

    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));
       _tcscat( code , lang );
       _tcscat( code , _T("-"));
       _tcscat( code , ctry );
       ::MessageBox( NULL , code , _T("Locale") , MB_OK );

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now