Skip to content
Permalink
Browse files

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.
  • Loading branch information
icculus committed May 4, 2020
1 parent 1e5dd06 commit fa23e3d00b461b707bdcf4693e231229d3ad863b
Showing with 1,318 additions and 4 deletions.
  1. +2 −0 Android.mk
  2. +43 −1 CMakeLists.txt
  3. +1 −0 Makefile.in
  4. +3 −1 Makefile.os2
  5. +4 −0 VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj
  6. +12 −0 VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters
  7. +4 −0 VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj
  8. +12 −0 VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters
  9. +4 −0 VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj
  10. +12 −0 VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters
  11. +4 −0 VisualC/SDL/SDL.vcxproj
  12. +6 −0 VisualC/SDL/SDL.vcxproj.filters
  13. +57 −0 Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj
  14. +64 −0 Xcode/SDL/SDL.xcodeproj/project.pbxproj
  15. +42 −1 configure
  16. +29 −0 configure.ac
  17. +1 −0 include/SDL.h
  18. +2 −0 include/SDL_events.h
  19. +15 −0 include/SDL_hints.h
  20. +101 −0 include/SDL_locale.h
  21. +78 −0 src/core/android/SDL_android.c
  22. +3 −0 src/core/android/SDL_android.h
  23. +1 −0 src/dynapi/SDL_dynapi_overrides.h
  24. +1 −0 src/dynapi/SDL_dynapi_procs.h
  25. +6 −0 src/events/SDL_events.c
  26. +1 −0 src/events/SDL_events_c.h
  27. +103 −0 src/locale/SDL_locale.c
  28. +29 −0 src/locale/SDL_syslocale.h
  29. +32 −0 src/locale/android/SDL_syslocale.c
  30. +33 −0 src/locale/dummy/SDL_syslocale.c
  31. +72 −0 src/locale/emscripten/SDL_syslocale.c
  32. +75 −0 src/locale/haiku/SDL_syslocale.cc
  33. +76 −0 src/locale/macosx/SDL_syslocale.m
  34. +110 −0 src/locale/unix/SDL_syslocale.c
  35. +119 −0 src/locale/windows/SDL_syslocale.c
  36. +58 −0 src/locale/winrt/SDL_syslocale.c
  37. +5 −0 src/main/haiku/SDL_BApp.h
  38. +12 −0 src/video/cocoa/SDL_cocoaevents.m
  39. +5 −0 test/Makefile.in
  40. +1 −0 test/README
  41. +13 −1 test/configure
  42. +67 −0 test/testlocale.c
@@ -35,6 +35,8 @@ LOCAL_SRC_FILES := \
$(wildcard $(LOCAL_PATH)/src/joystick/hidapi/*.c) \
$(wildcard $(LOCAL_PATH)/src/joystick/virtual/*.c) \
$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c) \
$(wildcard $(LOCAL_PATH)/src/locale/*.c) \
$(wildcard $(LOCAL_PATH)/src/locale/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/power/*.c) \
$(wildcard $(LOCAL_PATH)/src/power/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/filesystem/android/*.c) \
@@ -307,7 +307,7 @@ endif()

set(SDL_SUBSYSTEMS
Atomic Audio Video Render Events Joystick Haptic Power Threads Timers
File Loadso CPUinfo Filesystem Dlopen Sensor)
File Loadso CPUinfo Filesystem Dlopen Sensor Locale)
foreach(_SUB ${SDL_SUBSYSTEMS})
string(TOUPPER ${_SUB} _OPT)
if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT)
@@ -404,6 +404,7 @@ file(GLOB SOURCE_FILES
${SDL2_SOURCE_DIR}/src/events/*.c
${SDL2_SOURCE_DIR}/src/file/*.c
${SDL2_SOURCE_DIR}/src/libm/*.c
${SDL2_SOURCE_DIR}/src/locale/*.c
${SDL2_SOURCE_DIR}/src/render/*.c
${SDL2_SOURCE_DIR}/src/render/*/*.c
${SDL2_SOURCE_DIR}/src/stdlib/*.c
@@ -885,6 +886,8 @@ if(SDL_POWER)
file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
endif()


# TODO: in configure.ac, the test for LOADSO and SDL_DLOPEN is a bit weird:
# if LOADSO is not wanted, SDL_LOADSO_DISABLED is set
# If however on Unix or APPLE dlopen() is detected via CheckDLOPEN(),
@@ -993,6 +996,11 @@ if(ANDROID)
set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_POWER_SOURCES})
set(HAVE_SDL_POWER TRUE)
endif()
if(SDL_LOCALE)
file(GLOB ANDROID_LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/android/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_LOCALE_SOURCES})
set(HAVE_SDL_LOCALE TRUE)
endif()
if(SDL_TIMERS)
set(SDL_TIMER_UNIX 1)
file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
@@ -1083,6 +1091,11 @@ elseif(EMSCRIPTEN)
set(SOURCE_FILES ${SOURCE_FILES} ${EM_POWER_SOURCES})
set(HAVE_SDL_POWER TRUE)
endif()
if(SDL_LOCALE)
file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/emscripten/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
set(HAVE_SDL_LOCALE TRUE)
endif()
if(SDL_TIMERS)
set(SDL_TIMER_UNIX 1)
file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
@@ -1272,6 +1285,12 @@ elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT RISCOS)
endif()
endif()

if(SDL_LOCALE)
file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/unix/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
set(HAVE_SDL_LOCALE TRUE)
endif()

if(SDL_FILESYSTEM)
set(SDL_FILESYSTEM_UNIX 1)
file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/unix/*.c)
@@ -1438,6 +1457,12 @@ elseif(WINDOWS)
set(HAVE_SDL_POWER TRUE)
endif()

if(SDL_LOCALE)
file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/windows/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
set(HAVE_SDL_LOCALE TRUE)
endif()

if(SDL_FILESYSTEM)
set(SDL_FILESYSTEM_WINDOWS 1)
file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/windows/*.c)
@@ -1629,6 +1654,12 @@ elseif(APPLE)
set(HAVE_SDL_POWER TRUE)
endif()

if(SDL_LOCALE)
file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/macosx/*.m)
set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
set(HAVE_SDL_LOCALE TRUE)
endif()

if(SDL_TIMERS)
set(SDL_TIMER_UNIX 1)
file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
@@ -1837,6 +1868,12 @@ elseif(HAIKU)
set(HAVE_SDL_TIMERS TRUE)
endif()

if(SDL_LOCALE)
file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/haiku/*.cc)
set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
set(HAVE_SDL_LOCALE TRUE)
endif()

CheckPTHREAD()

elseif(RISCOS)
@@ -1899,6 +1936,11 @@ if(NOT HAVE_SDL_FILESYSTEM)
file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
endif()
if(NOT HAVE_SDL_LOCALE)
set(SDL_LOCALE_DISABLED 1)
file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/dummy/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
endif()

# We always need to have threads and timers around
if(NOT HAVE_SDL_THREADS)
@@ -82,6 +82,7 @@ HDRS = \
SDL_keyboard.h \
SDL_keycode.h \
SDL_loadso.h \
SDL_locale.h \
SDL_log.h \
SDL_main.h \
SDL_messagebox.h \
@@ -60,6 +60,8 @@ SRCS+= SDL_dummysensor.c

SRCS+= SDL_dynapi.c

SRCS+= SDL_locale.c SDL_syslocale.c

OBJS = $(SRCS:.c=.obj)
MOBJS= $(MSRCS:.c=.obj)

@@ -68,7 +70,7 @@ MOBJS= $(MSRCS:.c=.obj)

.c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/atomic;./src/audio/disk;
.c: ./src/haptic/dummy;./src/joystick/dummy;./src/audio/dummy;./src/video/dummy;./src/sensor/dummy;
.c: ./src/loadso/dummy;./src/filesystem/dummy;./src/timer/dummy;./src/thread/generic;
.c: ./src/loadso/dummy;./src/filesystem/dummy;./src/timer/dummy;./src/thread/generic;./src/locale/unix

all: $(DLLFILE) $(LIBFILE) .symbolic

@@ -52,6 +52,7 @@
<ClInclude Include="..\..\include\SDL_keyboard.h" />
<ClInclude Include="..\..\include\SDL_keycode.h" />
<ClInclude Include="..\..\include\SDL_loadso.h" />
<ClInclude Include="..\..\include\SDL_locale.h" />
<ClInclude Include="..\..\include\SDL_log.h" />
<ClInclude Include="..\..\include\SDL_main.h" />
<ClInclude Include="..\..\include\SDL_mouse.h" />
@@ -118,6 +119,7 @@
<ClInclude Include="..\..\src\joystick\windows\SDL_dinputjoystick_c.h" />
<ClInclude Include="..\..\src\joystick\windows\SDL_windowsjoystick_c.h" />
<ClInclude Include="..\..\src\joystick\windows\SDL_xinputjoystick_c.h" />
<ClInclude Include="..\..\src\locale\SDL_syslocale.h" />
<ClInclude Include="..\..\src\render\direct3d11\SDL_render_winrt.h" />
<ClInclude Include="..\..\src\render\direct3d11\SDL_shaders_d3d11.h" />
<ClInclude Include="..\..\src\render\opengles2\SDL_gles2funcs.h" />
@@ -249,6 +251,8 @@
<ClCompile Include="..\..\src\joystick\windows\SDL_windowsjoystick.c" />
<ClCompile Include="..\..\src\joystick\windows\SDL_xinputjoystick.c" />
<ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
<ClCompile Include="..\..\src\locale\SDL_locale.c" />
<ClCompile Include="..\..\src\locale\winrt\SDL_syslocale.c" />
<ClCompile Include="..\..\src\power\SDL_power.c" />
<ClCompile Include="..\..\src\power\winrt\SDL_syspower.cpp" />
<ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.c" />
@@ -84,6 +84,9 @@
<ClInclude Include="..\..\include\SDL_loadso.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL_locale.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL_log.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -321,6 +324,9 @@
<ClInclude Include="..\..\src\SDL_internal.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\locale\SDL_syslocale.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\thread\SDL_systhread.h">
<Filter>Source Files</Filter>
</ClInclude>
@@ -614,6 +620,12 @@
<ClCompile Include="..\..\src\SDL_log.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\locale\SDL_locale.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\locale\winrt\SDL_syslocale.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\stdlib\SDL_getenv.c">
<Filter>Source Files</Filter>
</ClCompile>
@@ -44,6 +44,7 @@
<ClInclude Include="..\..\include\SDL_keyboard.h" />
<ClInclude Include="..\..\include\SDL_keycode.h" />
<ClInclude Include="..\..\include\SDL_loadso.h" />
<ClInclude Include="..\..\include\SDL_locale.h" />
<ClInclude Include="..\..\include\SDL_log.h" />
<ClInclude Include="..\..\include\SDL_main.h" />
<ClInclude Include="..\..\include\SDL_mouse.h" />
@@ -124,6 +125,7 @@
<ClInclude Include="..\..\src\SDL_fatal.h" />
<ClInclude Include="..\..\src\SDL_hints_c.h" />
<ClInclude Include="..\..\src\SDL_internal.h" />
<ClInclude Include="..\..\src\locale\SDL_syslocale.h" />
<ClInclude Include="..\..\src\sensor\dummy\SDL_dummysensor.h" />
<ClInclude Include="..\..\src\sensor\SDL_sensor_c.h" />
<ClInclude Include="..\..\src\sensor\SDL_syssensor.h" />
@@ -245,6 +247,8 @@
<ClCompile Include="..\..\src\SDL_error.c" />
<ClCompile Include="..\..\src\SDL_hints.c" />
<ClCompile Include="..\..\src\SDL_log.c" />
<ClCompile Include="..\..\src\locale\SDL_locale.c" />
<ClCompile Include="..\..\src\locale\winrt\SDL_syslocale.c" />
<ClCompile Include="..\..\src\sensor\dummy\SDL_dummysensor.c" />
<ClCompile Include="..\..\src\sensor\SDL_sensor.c" />
<ClCompile Include="..\..\src\stdlib\SDL_getenv.c" />
@@ -84,6 +84,9 @@
<ClInclude Include="..\..\include\SDL_loadso.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL_locale.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL_log.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -306,6 +309,9 @@
<ClInclude Include="..\..\src\SDL_internal.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\locale\SDL_syslocale.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\thread\SDL_systhread.h">
<Filter>Source Files</Filter>
</ClInclude>
@@ -578,6 +584,12 @@
<ClCompile Include="..\..\src\SDL_log.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\locale\SDL_locale.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\locale\winrt\SDL_syslocale.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\stdlib\SDL_getenv.c">
<Filter>Source Files</Filter>
</ClCompile>
@@ -52,6 +52,7 @@
<ClInclude Include="..\..\include\SDL_keyboard.h" />
<ClInclude Include="..\..\include\SDL_keycode.h" />
<ClInclude Include="..\..\include\SDL_loadso.h" />
<ClInclude Include="..\..\include\SDL_locale.h" />
<ClInclude Include="..\..\include\SDL_log.h" />
<ClInclude Include="..\..\include\SDL_main.h" />
<ClInclude Include="..\..\include\SDL_mouse.h" />
@@ -139,6 +140,7 @@
<ClInclude Include="..\..\src\SDL_fatal.h" />
<ClInclude Include="..\..\src\SDL_hints_c.h" />
<ClInclude Include="..\..\src\SDL_internal.h" />
<ClInclude Include="..\..\src\locale\SDL_syslocale.h" />
<ClInclude Include="..\..\src\sensor\dummy\SDL_dummysensor.h" />
<ClInclude Include="..\..\src\sensor\SDL_sensor_c.h" />
<ClInclude Include="..\..\src\sensor\SDL_syssensor.h" />
@@ -277,6 +279,8 @@
<ClCompile Include="..\..\src\SDL_error.c" />
<ClCompile Include="..\..\src\SDL_hints.c" />
<ClCompile Include="..\..\src\SDL_log.c" />
<ClInclude Include="..\..\src\locale\SDL_locale.c" />
<ClInclude Include="..\..\src\locale\winrt\SDL_syslocale.c" />
<ClCompile Include="..\..\src\sensor\dummy\SDL_dummysensor.c" />
<ClCompile Include="..\..\src\sensor\SDL_sensor.c" />
<ClCompile Include="..\..\src\stdlib\SDL_getenv.c" />
@@ -84,6 +84,9 @@
<ClInclude Include="..\..\include\SDL_loadso.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL_locale.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL_log.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -306,6 +309,9 @@
<ClInclude Include="..\..\src\SDL_internal.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\locale\SDL_syslocale.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\thread\SDL_thread_c.h">
<Filter>Source Files</Filter>
</ClInclude>
@@ -596,6 +602,12 @@
<ClCompile Include="..\..\src\SDL_log.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\locale\SDL_locale.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\locale\winrt\SDL_syslocale.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\stdlib\SDL_getenv.c">
<Filter>Source Files</Filter>
</ClCompile>
@@ -239,6 +239,7 @@
<ClInclude Include="..\..\include\SDL_keyboard.h" />
<ClInclude Include="..\..\include\SDL_keycode.h" />
<ClInclude Include="..\..\include\SDL_loadso.h" />
<ClInclude Include="..\..\include\SDL_locale.h" />
<ClInclude Include="..\..\include\SDL_log.h" />
<ClInclude Include="..\..\include\SDL_main.h" />
<ClInclude Include="..\..\include\SDL_messagebox.h" />
@@ -331,6 +332,7 @@
<ClInclude Include="..\..\src\joystick\windows\SDL_xinputjoystick_c.h" />
<ClInclude Include="..\..\src\libm\math_libm.h" />
<ClInclude Include="..\..\src\libm\math_private.h" />
<ClInclude Include="..\..\src\locale\SDL_syslocale.h" />
<ClInclude Include="..\..\src\render\direct3d11\SDL_shaders_d3d11.h" />
<ClInclude Include="..\..\src\render\direct3d\SDL_shaders_d3d.h" />
<ClInclude Include="..\..\src\render\opengl\SDL_glfuncs.h" />
@@ -463,6 +465,8 @@
<ClCompile Include="..\..\src\libm\s_sin.c" />
<ClCompile Include="..\..\src\libm\s_tan.c" />
<ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
<ClCompile Include="..\..\src\locale\SDL_locale.c" />
<ClCompile Include="..\..\src\locale\windows\SDL_syslocale.c" />
<ClCompile Include="..\..\src\power\SDL_power.c" />
<ClCompile Include="..\..\src\power\windows\SDL_syspower.c" />
<ClCompile Include="..\..\src\render\direct3d11\SDL_shaders_d3d11.c" />
@@ -84,6 +84,9 @@
<ClInclude Include="..\..\include\SDL_loadso.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL_locale.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL_log.h">
<Filter>API Headers</Filter>
</ClInclude>
@@ -269,6 +272,7 @@
<ClInclude Include="..\..\src\joystick\windows\SDL_xinputjoystick_c.h" />
<ClInclude Include="..\..\src\libm\math_libm.h" />
<ClInclude Include="..\..\src\libm\math_private.h" />
<ClInclude Include="..\..\src\locale\SDL_syslocale.h" />
<ClInclude Include="..\..\src\render\direct3d\SDL_shaders_d3d.h" />
<ClInclude Include="..\..\src\render\direct3d11\SDL_shaders_d3d11.h" />
<ClInclude Include="..\..\src\render\opengl\SDL_glfuncs.h" />
@@ -401,6 +405,8 @@
<ClCompile Include="..\..\src\libm\s_sin.c" />
<ClCompile Include="..\..\src\libm\s_tan.c" />
<ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
<ClCompile Include="..\..\src\locale\SDL_locale.c" />
<ClCompile Include="..\..\src\locale\windows\SDL_syslocale.c" />
<ClCompile Include="..\..\src\power\SDL_power.c" />
<ClCompile Include="..\..\src\power\windows\SDL_syspower.c" />
<ClCompile Include="..\..\src\render\direct3d\SDL_render_d3d.c" />

0 comments on commit fa23e3d

Please sign in to comment.