locale: Implemented SDL_GetPreferredLocales().

This was something I proposed a long time ago, Sylvain Becker did
additional work on it, then back to me.

Fixes Bugzilla #2131.
This commit is contained in:
Ryan C. Gordon
2020-05-04 02:27:29 -04:00
parent 1e5dd06f83
commit fa23e3d00b
42 changed files with 1318 additions and 4 deletions

View File

@@ -37,6 +37,7 @@ TARGETS = \
testjoystick$(EXE) \
testkeys$(EXE) \
testloadso$(EXE) \
testlocale$(EXE) \
testlock$(EXE) \
testmessage$(EXE) \
testmultiaudio$(EXE) \
@@ -303,6 +304,10 @@ controllermap$(EXE): $(srcdir)/controllermap.c
testvulkan$(EXE): $(srcdir)/testvulkan.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testlocale$(EXE): $(srcdir)/testlocale.c
$(CC) -o $@ $? $(CFLAGS) $(LIBS)
clean:
rm -f $(TARGETS)

View File

@@ -12,6 +12,7 @@ These are test programs for the SDL library:
testjoystick List joysticks and watch joystick events
testkeys List the available keyboard keys
testloadso Tests the loadable library layer
testlocale Test Locale API
testlock Hacked up test of multi-threading and locking
testmultiaudio Tests using several audio devices
testoverlay2 Tests the overlay flickering/scaling during playback.

14
test/configure vendored
View File

@@ -640,6 +640,7 @@ infodir
docdir
oldincludedir
includedir
runstatedir
localstatedir
sharedstatedir
sysconfdir
@@ -720,6 +721,7 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE}'
@@ -972,6 +974,15 @@ do
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;
-runstatedir | --runstatedir | --runstatedi | --runstated \
| --runstate | --runstat | --runsta | --runst | --runs \
| --run | --ru | --r)
ac_prev=runstatedir ;;
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
| --run=* | --ru=* | --r=*)
runstatedir=$ac_optarg ;;
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1109,7 +1120,7 @@ fi
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
libdir localedir mandir
libdir localedir mandir runstatedir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
@@ -1262,6 +1273,7 @@ Fine tuning of the installation directories:
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]

67
test/testlocale.c Normal file
View File

@@ -0,0 +1,67 @@
/*
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
#include <stdio.h>
#include "SDL.h"
/* !!! FIXME: move this to the test framework */
static void log_locales(void)
{
SDL_Locale *locales = SDL_GetPreferredLocales();
if (locales == NULL) {
SDL_Log("Couldn't determine locales: %s", SDL_GetError());
} else {
SDL_Locale *l;
unsigned int total = 0;
SDL_Log("Locales, in order of preference:");
for (l = locales; l->language; l++) {
const char *c = l->country;
SDL_Log(" - %s%s%s", l->language, c ? "_" : "", c ? c : "");
total++;
}
SDL_Log("%u locales seen.", total);
SDL_free(locales);
}
}
int main(int argc, char **argv)
{
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Print locales and languages */
if (SDL_Init(SDL_INIT_VIDEO) != -1) {
log_locales();
if ((argc == 2) && (SDL_strcmp(argv[1], "--listen") == 0)) {
SDL_bool keep_going = SDL_TRUE;
while (keep_going) {
SDL_Event e;
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT) {
keep_going = SDL_FALSE;
} else if (e.type == SDL_LOCALECHANGED) {
SDL_Log("Saw SDL_LOCALECHANGED event!");
log_locales();
}
}
SDL_Delay(10);
}
}
SDL_Quit();
}
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */