9

On *nix systems you can do locale -a to get a list of available locales.

What is the equivalent command (or action) in Windows?

I've seen lists on the Internet, but most of them are of just locale labels and not actual locale names. Plus, not all systems are guaranteed to have all of them installed, right?

Note that my definition of "locale" here is "locale string", i.e. a second parameter to C's setlocale() which will result in a non-NULL return value.

Programmatic answers are also fine, I'm just tired of brute force guessing Windows locale names.

aib
  • 45,516
  • 10
  • 73
  • 79

2 Answers2

7

Initially, I couldn't find a C/Win32 API to get the information. (See later edit.) However, it looks like the .NET class System.Globalization.CultureInfo could provide the information you need. In particular, see CultureInfo.GetCultures(). This page seems to have a complete example of what you are looking for.

EDIT: If you prefer a C/Win32 API, see EnumSystemLocales() function.

EDIT 2: This example shows how to convert an LCID (which you get from EnumSystemLocales()) into a string useable by setlocale().

Supernovah
  • 1,946
  • 12
  • 34
  • 50
Eric Pi
  • 1,904
  • 12
  • 13
  • Very nice locale information there, but still no locale string usable by setlocale(). – aib Mar 01 '11 at 11:48
  • The [last] example is a start, but I wonder how it handles locales with multiple codepages (not to mention languages or country/regions). Looks like it only fetches the default ANSI code page or the default code page if it doesn't exist. There seem to be default EBCDIC and MAC code pages as well. Not that it matters; I got my answer: No such utility exists; one has to read through the poor NLS documentation and generate and eliminate locale names programmatically. – aib Mar 01 '11 at 12:25
2

This page seems to contain links to lists of language and country/region that the WIN32 setlocale recognizes. However:

The set of available languages, country/region codes, and code pages includes all those supported by the Win32 NLS API except code pages that require more than two bytes per character, such as UTF-7 and UTF-8. If you provide a code page like UTF-7 or UTF-8, setlocale will fail, returning NULL.

fail.

aib
  • 45,516
  • 10
  • 73
  • 79
  • 1
    I'm still curious about the UTF-16 support, however. – aib Mar 01 '11 at 12:26
  • Not to speak of UTF-32. I.e. why not? :) – mlvljr Apr 01 '11 at 12:29
  • @mlvljr: *shrug* I guess it's because UTF-32 definitely requires more than two bytes per character (so does UTF-16, but UTF-32 does more - some requirements are more required than others?) Though come to think of it, UTF-32's much easier to implement. – aib Apr 03 '11 at 05:09