gflohr has asked for the wisdom of the Perl Monks concerning the following question:
The Microsoft documentation for setlocale() suggests that - since 2018 - they support UTF-8 locales and short (Unix-style) locale identifiers like "en_US". However, I cannot get that to work, not even with Microsoft's own example code. The linked page also contains the up-to-date documentation for setlocale() on Windows.
I'm running a recent Windows 10 system inside VirtualBox. I have tried to switch the locale with (Strawberry) Perl and two versions of MinGW gcc. The result is always the same. I can set the locale to something like "German_Germany.1252" but none of "de_DE", "de-DE", "German_Germany.UTF-8", ".UTF8", "German_Germany.65001", ... work. 65001 is the "code page" for utf-8.
Can anybody shed some light on this?
I'm using this C code for testing (run with "PROGRAMNAME LOCALE"):
#include <locale.h> #include <stdio.h> #include <time.h> #include <string.h> int main(int argc, char *argv[]) { char date[256]; time_t then = 1678658400; const char *locale = setlocale(LC_TIME, argv[1]); strftime(date, sizeof date, "%B", localtime(&then)); printf("%s: %s (%u bytes)\n", locale, date, strlen(date)); return 0; }
Or in Perl
use v5.10; use POSIX qw(LC_ALL setlocale strftime); my $locale = $ARGV[0]; say "$locale: ", POSIX::setlocale(LC_ALL, $locale); my $march = strftime("%B", 0, 0, 0, 1, 2, 123); say $march;
On non-Windows systems, both versions invoked as "./PROGRAM de_DE.UTF-8" spit out the German word for the month march "März" in utf-8.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using setlocale() on Windows with utf-8 support
by syphilis (Archbishop) on Jul 18, 2023 at 01:21 UTC | |
|
Re: Using setlocale() on Windows with utf-8 support
by gflohr (Acolyte) on Jul 18, 2023 at 10:00 UTC | |
by syphilis (Archbishop) on Jul 18, 2023 at 12:49 UTC | |
by gflohr (Acolyte) on Jul 19, 2023 at 17:51 UTC | |
by syphilis (Archbishop) on Sep 11, 2023 at 11:32 UTC |