where can I find a list of locale names to use with std::locale in the Windows 11 operating system?

Hi,

I have looked everywhere for a list of locale names to use in Windows 11 with the std::locale type and no success.
Can somebody point me to such a list?

Regards,
Juan
Try something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <vector>
#include <string>
#include <iostream>

static BOOL CALLBACK myEnumSystemLocalesExCallback(LPWSTR name, DWORD flags, LPARAM param)
{
    std::vector<std::wstring> *const list = (std::vector<std::wstring>*)param;
    list->push_back(std::wstring(name));
    return TRUE;
}

int main()
{
    std::vector<std::wstring> locales;
    EnumSystemLocalesEx(myEnumSystemLocalesExCallback, LOCALE_ALL, (LPARAM)&locales, NULL);

    for (std::vector<std::wstring>::const_iterator iter = locales.cbegin(); iter != locales.cend(); ++iter) {
        std::wcout << *iter << std::endl;
    }
}
Last edited on
thanks:
However when I try to use the locale for Costa Rican spanish ("es-CR"), I don't get the output for numbers with the format used in Costa Rica (which represents 1000.75 as 1.000,75) but as represented in USA (1000.75 as 1,000.75)...??

Could this be some setting in my windows language-region that is getting on the way?

I don't know. This is what I get:
1
2
3
4
5
6
7
8
9
10
11
std::locale test_us("en-US");
std::wcout.imbue(test_us);
std::wcout << 10101.101 << L" <-- " << test_us.name().c_str() << std::endl;

std::locale test_de("de-DE");
std::wcout.imbue(test_de);
std::wcout << 10101.101 << L" <-- " << test_de.name().c_str() << std::endl;

std::locale test_cr("es-CR");
std::wcout.imbue(test_cr);
std::wcout << 10101.101 << L" <-- " << test_cr.name().c_str() << std::endl;
10,101.1 <-- en-US
10.101,1 <-- de-DE
10á101,1 <-- es-CR
Last edited on
weird!!
that looks like a unicode (probably not?) or dos console goobering (more likely) more than a bug. A few things just won't print right into a command prompt, esp if the prompt is on another locale than the code is using.

All that to say there are only like 6 number formats shared across hundreds of countries. You can check to see if another one that shares with CR is also borked and run down if its a bug or a console representation issue.

If you are printing to the console/terminal on Windows, then that is exactly the problem.

I have never failed by converting to UTF-16 and printing using the Windows console I/O routines.

It is why I wrote https://github.com/Duthomhas/utf8_console

You can look at the (shockingly simple) magic that makes UTF-8 I/O work by examining the utf8_console.cpp file:

  • duthomhas::utf8::console::Input streambuf for console input
  • duthomhas::utf8::console::Output streambuf for console output
  • duthomhas::utf8::console::initialize() sets everything up for you

The rest of the file is just to hijack main() and fix the command-line arguments to UTF-8 as well, but you can ignore that.

The point is you can use similar magic to hijack cout, etc to properly format your stuff.


(I am considering updating utf8_console to enable alternate methods for fixing main()’s arguments.)
Last edited on
Topic archived. No new replies allowed.