From 5a079a2d114f96d4847d1ee305d5b7c16eeec50e Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 27 Dec 2025 12:03:39 -0800 Subject: Initial commit --- contrib/SDL-3.2.8/src/locale/SDL_locale.c | 112 +++++++++++++++++++++ contrib/SDL-3.2.8/src/locale/SDL_syslocale.h | 33 ++++++ .../SDL-3.2.8/src/locale/android/SDL_syslocale.c | 29 ++++++ contrib/SDL-3.2.8/src/locale/dummy/SDL_syslocale.c | 29 ++++++ .../src/locale/emscripten/SDL_syslocale.c | 71 +++++++++++++ .../SDL-3.2.8/src/locale/haiku/SDL_syslocale.cc | 72 +++++++++++++ contrib/SDL-3.2.8/src/locale/macos/SDL_syslocale.m | 76 ++++++++++++++ contrib/SDL-3.2.8/src/locale/n3ds/SDL_syslocale.c | 55 ++++++++++ contrib/SDL-3.2.8/src/locale/psp/SDL_syslocale.c | 78 ++++++++++++++ contrib/SDL-3.2.8/src/locale/unix/SDL_syslocale.c | 103 +++++++++++++++++++ contrib/SDL-3.2.8/src/locale/vita/SDL_syslocale.c | 69 +++++++++++++ .../SDL-3.2.8/src/locale/windows/SDL_syslocale.c | 111 ++++++++++++++++++++ 12 files changed, 838 insertions(+) create mode 100644 contrib/SDL-3.2.8/src/locale/SDL_locale.c create mode 100644 contrib/SDL-3.2.8/src/locale/SDL_syslocale.h create mode 100644 contrib/SDL-3.2.8/src/locale/android/SDL_syslocale.c create mode 100644 contrib/SDL-3.2.8/src/locale/dummy/SDL_syslocale.c create mode 100644 contrib/SDL-3.2.8/src/locale/emscripten/SDL_syslocale.c create mode 100644 contrib/SDL-3.2.8/src/locale/haiku/SDL_syslocale.cc create mode 100644 contrib/SDL-3.2.8/src/locale/macos/SDL_syslocale.m create mode 100644 contrib/SDL-3.2.8/src/locale/n3ds/SDL_syslocale.c create mode 100644 contrib/SDL-3.2.8/src/locale/psp/SDL_syslocale.c create mode 100644 contrib/SDL-3.2.8/src/locale/unix/SDL_syslocale.c create mode 100644 contrib/SDL-3.2.8/src/locale/vita/SDL_syslocale.c create mode 100644 contrib/SDL-3.2.8/src/locale/windows/SDL_syslocale.c (limited to 'contrib/SDL-3.2.8/src/locale') diff --git a/contrib/SDL-3.2.8/src/locale/SDL_locale.c b/contrib/SDL-3.2.8/src/locale/SDL_locale.c new file mode 100644 index 0000000..09e011b --- /dev/null +++ b/contrib/SDL-3.2.8/src/locale/SDL_locale.c @@ -0,0 +1,112 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2025 Sam Lantinga + + 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, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_internal.h" +#include "SDL_syslocale.h" + +static SDL_Locale **build_locales_from_csv_string(char *csv, int *count) +{ + int i, num_locales; + size_t slen; + size_t alloclen; + char *ptr; + SDL_Locale *loc; + SDL_Locale **result; + + if (count) { + *count = 0; + } + + while (csv && *csv && SDL_isspace(*csv)) { + ++csv; + } + if (!csv || !*csv) { + return NULL; // nothing to report + } + + num_locales = 1; // at least one + for (ptr = csv; *ptr; ptr++) { + if (*ptr == ',') { + num_locales++; + } + } + + slen = ((size_t)(ptr - csv)) + 1; // SDL_strlen(csv) + 1 + alloclen = ((num_locales + 1) * sizeof(SDL_Locale *)) + (num_locales * sizeof(SDL_Locale)) + slen; + + result = (SDL_Locale **)SDL_calloc(1, alloclen); + if (!result) { + return NULL; // oh well + } + loc = (SDL_Locale *)(result + (num_locales + 1)); + ptr = (char *)(loc + num_locales); + SDL_memcpy(ptr, csv, slen); + + i = 0; + result[i++] = loc; + while (true) { // parse out the string + while (SDL_isspace(*ptr)) { + ptr++; // skip whitespace. + } + + if (*ptr == '\0') { + break; + } + loc->language = ptr++; + while (true) { + const char ch = *ptr; + if (ch == '_') { + *(ptr++) = '\0'; + loc->country = ptr; + } else if (SDL_isspace(ch)) { + *(ptr++) = '\0'; // trim ending whitespace and keep going. + } else if (ch == ',') { + *(ptr++) = '\0'; + loc++; + result[i++] = loc; + break; + } else if (ch == '\0') { + break; + } else { + ptr++; // just keep going, still a valid string + } + } + } + + if (count) { + *count = num_locales; + } + + return result; +} + +SDL_Locale **SDL_GetPreferredLocales(int *count) +{ + char locbuf[128]; // enough for 21 "xx_YY," language strings. + const char *hint = SDL_GetHint(SDL_HINT_PREFERRED_LOCALES); + if (hint) { + SDL_strlcpy(locbuf, hint, sizeof(locbuf)); + } else { + SDL_zeroa(locbuf); + SDL_SYS_GetPreferredLocales(locbuf, sizeof(locbuf)); + } + return build_locales_from_csv_string(locbuf, count); +} diff --git a/contrib/SDL-3.2.8/src/locale/SDL_syslocale.h b/contrib/SDL-3.2.8/src/locale/SDL_syslocale.h new file mode 100644 index 0000000..40b805d --- /dev/null +++ b/contrib/SDL-3.2.8/src/locale/SDL_syslocale.h @@ -0,0 +1,33 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2025 Sam Lantinga + + 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, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "SDL_internal.h" + +// This is the system specific header for the SDL locale API + +#ifdef __cplusplus +extern "C" { +#endif + +extern bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen); + +#ifdef __cplusplus +} +#endif diff --git a/contrib/SDL-3.2.8/src/locale/android/SDL_syslocale.c b/contrib/SDL-3.2.8/src/locale/android/SDL_syslocale.c new file mode 100644 index 0000000..da13ee4 --- /dev/null +++ b/contrib/SDL-3.2.8/src/locale/android/SDL_syslocale.c @@ -0,0 +1,29 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2025 Sam Lantinga + + 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, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_internal.h" +#include "../SDL_syslocale.h" +#include "../../core/android/SDL_android.h" + +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +{ + return Android_JNI_GetLocale(buf, buflen); +} diff --git a/contrib/SDL-3.2.8/src/locale/dummy/SDL_syslocale.c b/contrib/SDL-3.2.8/src/locale/dummy/SDL_syslocale.c new file mode 100644 index 0000000..f6cf9d7 --- /dev/null +++ b/contrib/SDL-3.2.8/src/locale/dummy/SDL_syslocale.c @@ -0,0 +1,29 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2025 Sam Lantinga + + 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, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_internal.h" +#include "../SDL_syslocale.h" + +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +{ + // dummy implementation. Caller already zero'd out buffer. + return SDL_Unsupported(); +} diff --git a/contrib/SDL-3.2.8/src/locale/emscripten/SDL_syslocale.c b/contrib/SDL-3.2.8/src/locale/emscripten/SDL_syslocale.c new file mode 100644 index 0000000..6983628 --- /dev/null +++ b/contrib/SDL-3.2.8/src/locale/emscripten/SDL_syslocale.c @@ -0,0 +1,71 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2025 Sam Lantinga + + 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, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include + +#include "SDL_internal.h" +#include "../SDL_syslocale.h" + +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +{ + /* *INDENT-OFF* */ // clang-format off + EM_ASM({ + var buf = $0; + var buflen = $1; + var list = undefined; + + if (navigator.languages && navigator.languages.length) { + list = navigator.languages; + } else { + var oneOfThese = navigator.userLanguage || navigator.language || navigator.browserLanguage || navigator.systemLanguage; + if (oneOfThese !== undefined) { + list = [ oneOfThese ]; + } + } + + if (list === undefined) { + return; // we've got nothing. + } + + var str = ""; // Can't do list.join() because we need to fit in buflen. + for (var i = 0; i < list.length; i++) { + var item = list[i]; + if ((str.length + item.length + 1) > buflen) { + break; // don't add, we're out of space. + } + if (str.length > 0) { + str += ","; + } + str += item; + } + + str = str.replace(/-/g, "_"); + if (buflen > str.length) { + buflen = str.length; // clamp to size of string. + } + + for (var i = 0; i < buflen; i++) { + setValue(buf + i, str.charCodeAt(i), "i8"); // fill in C array. + } + }, buf, buflen); + /* *INDENT-ON* */ // clang-format on + return true; +} diff --git a/contrib/SDL-3.2.8/src/locale/haiku/SDL_syslocale.cc b/contrib/SDL-3.2.8/src/locale/haiku/SDL_syslocale.cc new file mode 100644 index 0000000..045b751 --- /dev/null +++ b/contrib/SDL-3.2.8/src/locale/haiku/SDL_syslocale.cc @@ -0,0 +1,72 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2025 Sam Lantinga + + 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, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include +#include +#include + +#include "SDL_internal.h" +#include "../SDL_syslocale.h" + +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +{ + BLocaleRoster *roster = BLocaleRoster::Default(); + roster->Refresh(); + + BMessage msg; + if (roster->GetPreferredLanguages(&msg) != B_OK) { + return SDL_SetError("BLocaleRoster couldn't get preferred languages"); + } + + const char *key = "language"; + type_code typ = B_ANY_TYPE; + int32 numlangs = 0; + if ((msg.GetInfo(key, &typ, &numlangs) != B_OK) || (typ != B_STRING_TYPE)) { + return SDL_SetError("BLocaleRoster message was wrong"); + } + + for (int32 i = 0; i < numlangs; i++) { + const char *str = NULL; + if (msg.FindString(key, i, &str) != B_OK) { + continue; + } + + const size_t len = SDL_strlen(str); + if (buflen <= len) { + break; // can't fit it, we're done. + } + + SDL_strlcpy(buf, str, buflen); + buf += len; + buflen -= len; + + if (i < (numlangs - 1)) { + if (buflen <= 1) { + break; // out of room, stop looking. + } + buf[0] = ','; // add a comma between entries. + buf[1] = '\0'; + buf++; + buflen--; + } + } + return true; +} diff --git a/contrib/SDL-3.2.8/src/locale/macos/SDL_syslocale.m b/contrib/SDL-3.2.8/src/locale/macos/SDL_syslocale.m new file mode 100644 index 0000000..6ea1761 --- /dev/null +++ b/contrib/SDL-3.2.8/src/locale/macos/SDL_syslocale.m @@ -0,0 +1,76 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2025 Sam Lantinga + + 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, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_internal.h" +#include "../SDL_syslocale.h" + +#import + +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +{ + @autoreleasepool { + NSArray *languages = NSLocale.preferredLanguages; + size_t numlangs = 0; + size_t i; + + numlangs = (size_t)[languages count]; + + for (i = 0; i < numlangs; i++) { + NSString *nsstr = [languages objectAtIndex:i]; + size_t len; + char *ptr; + + if (nsstr == nil) { + break; + } + + [nsstr getCString:buf maxLength:buflen encoding:NSASCIIStringEncoding]; + len = SDL_strlen(buf); + + // convert '-' to '_'... + // These are always full lang-COUNTRY, so we search from the back, + // so things like zh-Hant-CN find the right '-' to convert. + ptr = SDL_strrchr(buf, '-'); + if (ptr != NULL) { + *ptr = '_'; + } + + if (buflen <= len) { + *buf = '\0'; // drop this one and stop, we can't fit anymore. + break; + } + + buf += len; + buflen -= len; + + if (i < (numlangs - 1)) { + if (buflen <= 1) { + break; // out of room, stop looking. + } + buf[0] = ','; // add a comma between entries. + buf[1] = '\0'; + buf++; + buflen--; + } + } + } + return true; +} diff --git a/contrib/SDL-3.2.8/src/locale/n3ds/SDL_syslocale.c b/contrib/SDL-3.2.8/src/locale/n3ds/SDL_syslocale.c new file mode 100644 index 0000000..5d0bbd3 --- /dev/null +++ b/contrib/SDL-3.2.8/src/locale/n3ds/SDL_syslocale.c @@ -0,0 +1,55 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2025 Sam Lantinga + + 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, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "../SDL_syslocale.h" +#include "SDL_internal.h" + +#include <3ds.h> + +// Used when the CFGU fails to work. +#define BAD_LOCALE 255 + +static u8 GetLocaleIndex(void); + +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +{ + // The 3DS only supports these 12 languages, only one can be active at a time + static const char AVAILABLE_LOCALES[][6] = { "ja_JP", "en_US", "fr_FR", "de_DE", + "it_IT", "es_ES", "zh_CN", "ko_KR", + "nl_NL", "pt_PT", "ru_RU", "zh_TW" }; + u8 current_locale = GetLocaleIndex(); + if (current_locale != BAD_LOCALE) { + SDL_strlcpy(buf, AVAILABLE_LOCALES[current_locale], buflen); + } + return true; +} + +static u8 GetLocaleIndex(void) +{ + u8 current_locale; + Result result; + if (R_FAILED(cfguInit())) { + return BAD_LOCALE; + } + result = CFGU_GetSystemLanguage(¤t_locale); + cfguExit(); + return R_SUCCEEDED(result) ? current_locale : BAD_LOCALE; +} diff --git a/contrib/SDL-3.2.8/src/locale/psp/SDL_syslocale.c b/contrib/SDL-3.2.8/src/locale/psp/SDL_syslocale.c new file mode 100644 index 0000000..4b5e1b9 --- /dev/null +++ b/contrib/SDL-3.2.8/src/locale/psp/SDL_syslocale.c @@ -0,0 +1,78 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2025 Sam Lantinga + + 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, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_internal.h" +#include "../SDL_syslocale.h" + +#include + +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +{ + int current_locale_int = PSP_SYSTEMPARAM_LANGUAGE_ENGLISH; + + SDL_assert(buflen > 0); + + sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, ¤t_locale_int); + switch(current_locale_int) { + case PSP_SYSTEMPARAM_LANGUAGE_JAPANESE: + SDL_strlcpy(buf, "ja_JP", buflen); + break; + case PSP_SYSTEMPARAM_LANGUAGE_ENGLISH: + SDL_strlcpy(buf, "en_US", buflen); + break; + case PSP_SYSTEMPARAM_LANGUAGE_FRENCH: + SDL_strlcpy(buf, "fr_FR", buflen); + break; + case PSP_SYSTEMPARAM_LANGUAGE_SPANISH: + SDL_strlcpy(buf, "es_ES", buflen); + break; + case PSP_SYSTEMPARAM_LANGUAGE_GERMAN: + SDL_strlcpy(buf, "de_DE", buflen); + break; + case PSP_SYSTEMPARAM_LANGUAGE_ITALIAN: + SDL_strlcpy(buf, "it_IT", buflen); + break; + case PSP_SYSTEMPARAM_LANGUAGE_DUTCH: + SDL_strlcpy(buf, "nl_NL", buflen); + break; + case PSP_SYSTEMPARAM_LANGUAGE_PORTUGUESE: + SDL_strlcpy(buf, "pt_PT", buflen); + break; + case PSP_SYSTEMPARAM_LANGUAGE_RUSSIAN: + SDL_strlcpy(buf, "ru_RU", buflen); + break; + case PSP_SYSTEMPARAM_LANGUAGE_KOREAN: + SDL_strlcpy(buf, "ko_KR", buflen); + break; + case PSP_SYSTEMPARAM_LANGUAGE_CHINESE_TRADITIONAL: + SDL_strlcpy(buf, "zh_TW", buflen); + break; + case PSP_SYSTEMPARAM_LANGUAGE_CHINESE_SIMPLIFIED: + SDL_strlcpy(buf, "zh_CN", buflen); + break; + default: + SDL_strlcpy(buf, "en_US", buflen); + break; + } + return true; +} + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/contrib/SDL-3.2.8/src/locale/unix/SDL_syslocale.c b/contrib/SDL-3.2.8/src/locale/unix/SDL_syslocale.c new file mode 100644 index 0000000..98c68c3 --- /dev/null +++ b/contrib/SDL-3.2.8/src/locale/unix/SDL_syslocale.c @@ -0,0 +1,103 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2025 Sam Lantinga + + 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, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_internal.h" +#include "../SDL_syslocale.h" + +static void normalize_locale_str(char *dst, char *str, size_t buflen) +{ + char *ptr; + + ptr = SDL_strchr(str, '.'); // chop off encoding if specified. + if (ptr) { + *ptr = '\0'; + } + + ptr = SDL_strchr(str, '@'); // chop off extra bits if specified. + if (ptr) { + *ptr = '\0'; + } + + // The "C" locale isn't useful for our needs, ignore it if you see it. + if ((str[0] == 'C') && (str[1] == '\0')) { + return; + } + + if (*str) { + if (*dst) { + SDL_strlcat(dst, ",", buflen); // SDL has these split by commas + } + SDL_strlcat(dst, str, buflen); + } +} + +static void normalize_locales(char *dst, char *src, size_t buflen) +{ + char *ptr; + + // entries are separated by colons + while ((ptr = SDL_strchr(src, ':')) != NULL) { + *ptr = '\0'; + normalize_locale_str(dst, src, buflen); + src = ptr + 1; + } + normalize_locale_str(dst, src, buflen); +} + +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +{ + // !!! FIXME: should we be using setlocale()? Or some D-Bus thing? + bool isstack; + const char *envr; + char *tmp; + + SDL_assert(buflen > 0); + tmp = SDL_small_alloc(char, buflen, &isstack); + if (!tmp) { + return false; + } + + *tmp = '\0'; + + // LANG is the primary locale (maybe) + envr = SDL_getenv("LANG"); + if (envr) { + SDL_strlcpy(tmp, envr, buflen); + } + + // fallback languages + envr = SDL_getenv("LANGUAGE"); + if (envr) { + if (*tmp) { + SDL_strlcat(tmp, ":", buflen); + } + SDL_strlcat(tmp, envr, buflen); + } + + if (*tmp == '\0') { + SDL_SetError("LANG environment variable isn't set"); + } else { + normalize_locales(buf, tmp, buflen); + } + + SDL_small_free(tmp, isstack); + return true; +} diff --git a/contrib/SDL-3.2.8/src/locale/vita/SDL_syslocale.c b/contrib/SDL-3.2.8/src/locale/vita/SDL_syslocale.c new file mode 100644 index 0000000..76a6f6a --- /dev/null +++ b/contrib/SDL-3.2.8/src/locale/vita/SDL_syslocale.c @@ -0,0 +1,69 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2025 Sam Lantinga + + 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, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_internal.h" +#include "../SDL_syslocale.h" + +#include +#include + +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +{ + const char *vita_locales[] = { + "ja_JP", + "en_US", + "fr_FR", + "es_ES", + "de_DE", + "it_IT", + "nl_NL", + "pt_PT", + "ru_RU", + "ko_KR", + "zh_TW", + "zh_CN", + "fi_FI", + "sv_SE", + "da_DK", + "no_NO", + "pl_PL", + "pt_BR", + "en_GB", + "tr_TR", + }; + + Sint32 language = SCE_SYSTEM_PARAM_LANG_ENGLISH_US; + SceAppUtilInitParam initParam; + SceAppUtilBootParam bootParam; + SDL_zero(initParam); + SDL_zero(bootParam); + sceAppUtilInit(&initParam, &bootParam); + sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_LANG, &language); + + if (language < 0 || language > SCE_SYSTEM_PARAM_LANG_TURKISH) { + language = SCE_SYSTEM_PARAM_LANG_ENGLISH_US; // default to english + } + + SDL_strlcpy(buf, vita_locales[language], buflen); + + sceAppUtilShutdown(); + return true; +} diff --git a/contrib/SDL-3.2.8/src/locale/windows/SDL_syslocale.c b/contrib/SDL-3.2.8/src/locale/windows/SDL_syslocale.c new file mode 100644 index 0000000..7f69c56 --- /dev/null +++ b/contrib/SDL-3.2.8/src/locale/windows/SDL_syslocale.c @@ -0,0 +1,111 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2025 Sam Lantinga + + 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, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_internal.h" +#include "../../core/windows/SDL_windows.h" +#include "../SDL_syslocale.h" + +typedef BOOL(WINAPI *pfnGetUserPreferredUILanguages)(DWORD, PULONG, WCHAR *, PULONG); +#ifndef MUI_LANGUAGE_NAME +#define MUI_LANGUAGE_NAME 0x8 +#endif + +static pfnGetUserPreferredUILanguages pGetUserPreferredUILanguages = NULL; +static HMODULE kernel32 = 0; + +// this is the fallback for WinXP...one language, not a list. +static bool SDL_SYS_GetPreferredLocales_winxp(char *buf, size_t buflen) +{ + char lang[16]; + char country[16]; + + const int langrc = GetLocaleInfoA(LOCALE_USER_DEFAULT, + LOCALE_SISO639LANGNAME, + lang, sizeof(lang)); + + const int ctryrc = GetLocaleInfoA(LOCALE_USER_DEFAULT, + LOCALE_SISO3166CTRYNAME, + country, sizeof(country)); + + /* Win95 systems will fail, because they don't have LOCALE_SISO*NAME ... */ + if (langrc == 0) { + return SDL_SetError("Couldn't obtain language info"); + } else { + (void)SDL_snprintf(buf, buflen, "%s%s%s", lang, ctryrc ? "_" : "", ctryrc ? country : ""); + return true; + } +} + +// this works on Windows Vista and later. +static bool SDL_SYS_GetPreferredLocales_vista(char *buf, size_t buflen) +{ + ULONG numlangs = 0; + WCHAR *wbuf = NULL; + ULONG wbuflen = 0; + bool isstack; + + SDL_assert(pGetUserPreferredUILanguages != NULL); + pGetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numlangs, NULL, &wbuflen); + + wbuf = SDL_small_alloc(WCHAR, wbuflen, &isstack); + if (!wbuf) { + return false; + } + + if (!pGetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numlangs, wbuf, &wbuflen)) { + SDL_SYS_GetPreferredLocales_winxp(buf, buflen); // oh well, try the fallback. + } else { + const ULONG endidx = (ULONG)SDL_min(buflen, wbuflen - 1); + ULONG str_start = 0; + ULONG i; + for (i = 0; i < endidx; i++) { + const char ch = (char)wbuf[i]; // these should all be low-ASCII, safe to cast + if (ch == '\0') { + buf[i] = ','; // change null separators to commas + str_start = i; + } else if (ch == '-') { + buf[i] = '_'; // change '-' to '_' + } else { + buf[i] = ch; // copy through as-is. + } + } + buf[str_start] = '\0'; // terminate string, chop off final ',' + } + + SDL_small_free(wbuf, isstack); + return true; +} + +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +{ + if (!kernel32) { + kernel32 = GetModuleHandle(TEXT("kernel32.dll")); + if (kernel32) { + pGetUserPreferredUILanguages = (pfnGetUserPreferredUILanguages)GetProcAddress(kernel32, "GetUserPreferredUILanguages"); + } + } + + if (!pGetUserPreferredUILanguages) { + return SDL_SYS_GetPreferredLocales_winxp(buf, buflen); // this is always available + } else { + return SDL_SYS_GetPreferredLocales_vista(buf, buflen); // available on Vista and later. + } +} -- cgit v1.2.3