How to find a list of supported locales in Windows?

need the names of supported locales in Windows please!
EnumSystemLocalesEx

https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-enumsystemlocalesex

Here is how to use it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <windows.h>
#include <iostream>
#include <vector>
#include <string>

static std::vector<std::wstring> locales;

BOOL __stdcall LocaleEnumProc(LPWSTR locale, [[maybe_unused]] DWORD flags, LPARAM data)
{
	const wchar_t* question = reinterpret_cast<const wchar_t*>(data);

	if (question != nullptr)
	{
		if (std::wstring(question).compare(locale) == 0)
		{
			locales.push_back(question);
			return FALSE;
		}
	}
	else
	{
		locales.push_back(locale);
	}

	return TRUE;
}

bool LocaleExists(const wchar_t* locale)
{
	locales.clear();
	const BOOL status = EnumSystemLocalesEx(
		LocaleEnumProc, LOCALE_WINDOWS, reinterpret_cast<LPARAM>(locale), nullptr);

	return (status != FALSE) && (!locales.empty());
}

int main()
{
	// Enumerate all locales on system
	EnumSystemLocalesEx(LocaleEnumProc, LOCALE_WINDOWS, 0, nullptr);

	for (const auto& ref : locales)
	{
		std::wcout << ref << std::endl;
	}

	// Check if specific locale exist on system
	if (LocaleExists(L"de-DE"))
	{
		std::wcout << L"de-DE exists" << std::endl;
	}
	else
	{
		std::wcout << L"de-DE does not exist" << std::endl;
	}

	return 0;
}
Last edited on
When using #include <windows.h>, consider also having before

1
2
3
4
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX

#include <windows.h> 


This prevents definition of the windows max and min macros (use std::algorithm max and min) and doesn't include some hardly-used windows includes (see https://learn.microsoft.com/en-us/windows/win32/winprog/using-the-windows-headers ) which reduces the compile time.
Topic archived. No new replies allowed.