diff options
Diffstat (limited to 'contrib/SDL-3.2.8/src/locale')
| -rw-r--r-- | contrib/SDL-3.2.8/src/locale/SDL_locale.c | 112 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/locale/SDL_syslocale.h | 33 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/locale/android/SDL_syslocale.c | 29 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/locale/dummy/SDL_syslocale.c | 29 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/locale/emscripten/SDL_syslocale.c | 71 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/locale/haiku/SDL_syslocale.cc | 72 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/locale/macos/SDL_syslocale.m | 76 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/locale/n3ds/SDL_syslocale.c | 55 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/locale/psp/SDL_syslocale.c | 78 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/locale/unix/SDL_syslocale.c | 103 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/locale/vita/SDL_syslocale.c | 69 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/locale/windows/SDL_syslocale.c | 111 |
12 files changed, 838 insertions, 0 deletions
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 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "SDL_internal.h" | ||
| 23 | #include "SDL_syslocale.h" | ||
| 24 | |||
| 25 | static SDL_Locale **build_locales_from_csv_string(char *csv, int *count) | ||
| 26 | { | ||
| 27 | int i, num_locales; | ||
| 28 | size_t slen; | ||
| 29 | size_t alloclen; | ||
| 30 | char *ptr; | ||
| 31 | SDL_Locale *loc; | ||
| 32 | SDL_Locale **result; | ||
| 33 | |||
| 34 | if (count) { | ||
| 35 | *count = 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | while (csv && *csv && SDL_isspace(*csv)) { | ||
| 39 | ++csv; | ||
| 40 | } | ||
| 41 | if (!csv || !*csv) { | ||
| 42 | return NULL; // nothing to report | ||
| 43 | } | ||
| 44 | |||
| 45 | num_locales = 1; // at least one | ||
| 46 | for (ptr = csv; *ptr; ptr++) { | ||
| 47 | if (*ptr == ',') { | ||
| 48 | num_locales++; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | slen = ((size_t)(ptr - csv)) + 1; // SDL_strlen(csv) + 1 | ||
| 53 | alloclen = ((num_locales + 1) * sizeof(SDL_Locale *)) + (num_locales * sizeof(SDL_Locale)) + slen; | ||
| 54 | |||
| 55 | result = (SDL_Locale **)SDL_calloc(1, alloclen); | ||
| 56 | if (!result) { | ||
| 57 | return NULL; // oh well | ||
| 58 | } | ||
| 59 | loc = (SDL_Locale *)(result + (num_locales + 1)); | ||
| 60 | ptr = (char *)(loc + num_locales); | ||
| 61 | SDL_memcpy(ptr, csv, slen); | ||
| 62 | |||
| 63 | i = 0; | ||
| 64 | result[i++] = loc; | ||
| 65 | while (true) { // parse out the string | ||
| 66 | while (SDL_isspace(*ptr)) { | ||
| 67 | ptr++; // skip whitespace. | ||
| 68 | } | ||
| 69 | |||
| 70 | if (*ptr == '\0') { | ||
| 71 | break; | ||
| 72 | } | ||
| 73 | loc->language = ptr++; | ||
| 74 | while (true) { | ||
| 75 | const char ch = *ptr; | ||
| 76 | if (ch == '_') { | ||
| 77 | *(ptr++) = '\0'; | ||
| 78 | loc->country = ptr; | ||
| 79 | } else if (SDL_isspace(ch)) { | ||
| 80 | *(ptr++) = '\0'; // trim ending whitespace and keep going. | ||
| 81 | } else if (ch == ',') { | ||
| 82 | *(ptr++) = '\0'; | ||
| 83 | loc++; | ||
| 84 | result[i++] = loc; | ||
| 85 | break; | ||
| 86 | } else if (ch == '\0') { | ||
| 87 | break; | ||
| 88 | } else { | ||
| 89 | ptr++; // just keep going, still a valid string | ||
| 90 | } | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | if (count) { | ||
| 95 | *count = num_locales; | ||
| 96 | } | ||
| 97 | |||
| 98 | return result; | ||
| 99 | } | ||
| 100 | |||
| 101 | SDL_Locale **SDL_GetPreferredLocales(int *count) | ||
| 102 | { | ||
| 103 | char locbuf[128]; // enough for 21 "xx_YY," language strings. | ||
| 104 | const char *hint = SDL_GetHint(SDL_HINT_PREFERRED_LOCALES); | ||
| 105 | if (hint) { | ||
| 106 | SDL_strlcpy(locbuf, hint, sizeof(locbuf)); | ||
| 107 | } else { | ||
| 108 | SDL_zeroa(locbuf); | ||
| 109 | SDL_SYS_GetPreferredLocales(locbuf, sizeof(locbuf)); | ||
| 110 | } | ||
| 111 | return build_locales_from_csv_string(locbuf, count); | ||
| 112 | } | ||
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 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | #include "SDL_internal.h" | ||
| 22 | |||
| 23 | // This is the system specific header for the SDL locale API | ||
| 24 | |||
| 25 | #ifdef __cplusplus | ||
| 26 | extern "C" { | ||
| 27 | #endif | ||
| 28 | |||
| 29 | extern bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen); | ||
| 30 | |||
| 31 | #ifdef __cplusplus | ||
| 32 | } | ||
| 33 | #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 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "SDL_internal.h" | ||
| 23 | #include "../SDL_syslocale.h" | ||
| 24 | #include "../../core/android/SDL_android.h" | ||
| 25 | |||
| 26 | bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) | ||
| 27 | { | ||
| 28 | return Android_JNI_GetLocale(buf, buflen); | ||
| 29 | } | ||
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 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "SDL_internal.h" | ||
| 23 | #include "../SDL_syslocale.h" | ||
| 24 | |||
| 25 | bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) | ||
| 26 | { | ||
| 27 | // dummy implementation. Caller already zero'd out buffer. | ||
| 28 | return SDL_Unsupported(); | ||
| 29 | } | ||
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 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <emscripten.h> | ||
| 23 | |||
| 24 | #include "SDL_internal.h" | ||
| 25 | #include "../SDL_syslocale.h" | ||
| 26 | |||
| 27 | bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) | ||
| 28 | { | ||
| 29 | /* *INDENT-OFF* */ // clang-format off | ||
| 30 | EM_ASM({ | ||
| 31 | var buf = $0; | ||
| 32 | var buflen = $1; | ||
| 33 | var list = undefined; | ||
| 34 | |||
| 35 | if (navigator.languages && navigator.languages.length) { | ||
| 36 | list = navigator.languages; | ||
| 37 | } else { | ||
| 38 | var oneOfThese = navigator.userLanguage || navigator.language || navigator.browserLanguage || navigator.systemLanguage; | ||
| 39 | if (oneOfThese !== undefined) { | ||
| 40 | list = [ oneOfThese ]; | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | if (list === undefined) { | ||
| 45 | return; // we've got nothing. | ||
| 46 | } | ||
| 47 | |||
| 48 | var str = ""; // Can't do list.join() because we need to fit in buflen. | ||
| 49 | for (var i = 0; i < list.length; i++) { | ||
| 50 | var item = list[i]; | ||
| 51 | if ((str.length + item.length + 1) > buflen) { | ||
| 52 | break; // don't add, we're out of space. | ||
| 53 | } | ||
| 54 | if (str.length > 0) { | ||
| 55 | str += ","; | ||
| 56 | } | ||
| 57 | str += item; | ||
| 58 | } | ||
| 59 | |||
| 60 | str = str.replace(/-/g, "_"); | ||
| 61 | if (buflen > str.length) { | ||
| 62 | buflen = str.length; // clamp to size of string. | ||
| 63 | } | ||
| 64 | |||
| 65 | for (var i = 0; i < buflen; i++) { | ||
| 66 | setValue(buf + i, str.charCodeAt(i), "i8"); // fill in C array. | ||
| 67 | } | ||
| 68 | }, buf, buflen); | ||
| 69 | /* *INDENT-ON* */ // clang-format on | ||
| 70 | return true; | ||
| 71 | } | ||
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 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <AppKit.h> | ||
| 23 | #include <LocaleRoster.h> | ||
| 24 | #include <TypeConstants.h> | ||
| 25 | |||
| 26 | #include "SDL_internal.h" | ||
| 27 | #include "../SDL_syslocale.h" | ||
| 28 | |||
| 29 | bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) | ||
| 30 | { | ||
| 31 | BLocaleRoster *roster = BLocaleRoster::Default(); | ||
| 32 | roster->Refresh(); | ||
| 33 | |||
| 34 | BMessage msg; | ||
| 35 | if (roster->GetPreferredLanguages(&msg) != B_OK) { | ||
| 36 | return SDL_SetError("BLocaleRoster couldn't get preferred languages"); | ||
| 37 | } | ||
| 38 | |||
| 39 | const char *key = "language"; | ||
| 40 | type_code typ = B_ANY_TYPE; | ||
| 41 | int32 numlangs = 0; | ||
| 42 | if ((msg.GetInfo(key, &typ, &numlangs) != B_OK) || (typ != B_STRING_TYPE)) { | ||
| 43 | return SDL_SetError("BLocaleRoster message was wrong"); | ||
| 44 | } | ||
| 45 | |||
| 46 | for (int32 i = 0; i < numlangs; i++) { | ||
| 47 | const char *str = NULL; | ||
| 48 | if (msg.FindString(key, i, &str) != B_OK) { | ||
| 49 | continue; | ||
| 50 | } | ||
| 51 | |||
| 52 | const size_t len = SDL_strlen(str); | ||
| 53 | if (buflen <= len) { | ||
| 54 | break; // can't fit it, we're done. | ||
| 55 | } | ||
| 56 | |||
| 57 | SDL_strlcpy(buf, str, buflen); | ||
| 58 | buf += len; | ||
| 59 | buflen -= len; | ||
| 60 | |||
| 61 | if (i < (numlangs - 1)) { | ||
| 62 | if (buflen <= 1) { | ||
| 63 | break; // out of room, stop looking. | ||
| 64 | } | ||
| 65 | buf[0] = ','; // add a comma between entries. | ||
| 66 | buf[1] = '\0'; | ||
| 67 | buf++; | ||
| 68 | buflen--; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | return true; | ||
| 72 | } | ||
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 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "SDL_internal.h" | ||
| 23 | #include "../SDL_syslocale.h" | ||
| 24 | |||
| 25 | #import <Foundation/Foundation.h> | ||
| 26 | |||
| 27 | bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) | ||
| 28 | { | ||
| 29 | @autoreleasepool { | ||
| 30 | NSArray *languages = NSLocale.preferredLanguages; | ||
| 31 | size_t numlangs = 0; | ||
| 32 | size_t i; | ||
| 33 | |||
| 34 | numlangs = (size_t)[languages count]; | ||
| 35 | |||
| 36 | for (i = 0; i < numlangs; i++) { | ||
| 37 | NSString *nsstr = [languages objectAtIndex:i]; | ||
| 38 | size_t len; | ||
| 39 | char *ptr; | ||
| 40 | |||
| 41 | if (nsstr == nil) { | ||
| 42 | break; | ||
| 43 | } | ||
| 44 | |||
| 45 | [nsstr getCString:buf maxLength:buflen encoding:NSASCIIStringEncoding]; | ||
| 46 | len = SDL_strlen(buf); | ||
| 47 | |||
| 48 | // convert '-' to '_'... | ||
| 49 | // These are always full lang-COUNTRY, so we search from the back, | ||
| 50 | // so things like zh-Hant-CN find the right '-' to convert. | ||
| 51 | ptr = SDL_strrchr(buf, '-'); | ||
| 52 | if (ptr != NULL) { | ||
| 53 | *ptr = '_'; | ||
| 54 | } | ||
| 55 | |||
| 56 | if (buflen <= len) { | ||
| 57 | *buf = '\0'; // drop this one and stop, we can't fit anymore. | ||
| 58 | break; | ||
| 59 | } | ||
| 60 | |||
| 61 | buf += len; | ||
| 62 | buflen -= len; | ||
| 63 | |||
| 64 | if (i < (numlangs - 1)) { | ||
| 65 | if (buflen <= 1) { | ||
| 66 | break; // out of room, stop looking. | ||
| 67 | } | ||
| 68 | buf[0] = ','; // add a comma between entries. | ||
| 69 | buf[1] = '\0'; | ||
| 70 | buf++; | ||
| 71 | buflen--; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | return true; | ||
| 76 | } | ||
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 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "../SDL_syslocale.h" | ||
| 23 | #include "SDL_internal.h" | ||
| 24 | |||
| 25 | #include <3ds.h> | ||
| 26 | |||
| 27 | // Used when the CFGU fails to work. | ||
| 28 | #define BAD_LOCALE 255 | ||
| 29 | |||
| 30 | static u8 GetLocaleIndex(void); | ||
| 31 | |||
| 32 | bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) | ||
| 33 | { | ||
| 34 | // The 3DS only supports these 12 languages, only one can be active at a time | ||
| 35 | static const char AVAILABLE_LOCALES[][6] = { "ja_JP", "en_US", "fr_FR", "de_DE", | ||
| 36 | "it_IT", "es_ES", "zh_CN", "ko_KR", | ||
| 37 | "nl_NL", "pt_PT", "ru_RU", "zh_TW" }; | ||
| 38 | u8 current_locale = GetLocaleIndex(); | ||
| 39 | if (current_locale != BAD_LOCALE) { | ||
| 40 | SDL_strlcpy(buf, AVAILABLE_LOCALES[current_locale], buflen); | ||
| 41 | } | ||
| 42 | return true; | ||
| 43 | } | ||
| 44 | |||
| 45 | static u8 GetLocaleIndex(void) | ||
| 46 | { | ||
| 47 | u8 current_locale; | ||
| 48 | Result result; | ||
| 49 | if (R_FAILED(cfguInit())) { | ||
| 50 | return BAD_LOCALE; | ||
| 51 | } | ||
| 52 | result = CFGU_GetSystemLanguage(¤t_locale); | ||
| 53 | cfguExit(); | ||
| 54 | return R_SUCCEEDED(result) ? current_locale : BAD_LOCALE; | ||
| 55 | } | ||
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 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "SDL_internal.h" | ||
| 23 | #include "../SDL_syslocale.h" | ||
| 24 | |||
| 25 | #include <psputility.h> | ||
| 26 | |||
| 27 | bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) | ||
| 28 | { | ||
| 29 | int current_locale_int = PSP_SYSTEMPARAM_LANGUAGE_ENGLISH; | ||
| 30 | |||
| 31 | SDL_assert(buflen > 0); | ||
| 32 | |||
| 33 | sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, ¤t_locale_int); | ||
| 34 | switch(current_locale_int) { | ||
| 35 | case PSP_SYSTEMPARAM_LANGUAGE_JAPANESE: | ||
| 36 | SDL_strlcpy(buf, "ja_JP", buflen); | ||
| 37 | break; | ||
| 38 | case PSP_SYSTEMPARAM_LANGUAGE_ENGLISH: | ||
| 39 | SDL_strlcpy(buf, "en_US", buflen); | ||
| 40 | break; | ||
| 41 | case PSP_SYSTEMPARAM_LANGUAGE_FRENCH: | ||
| 42 | SDL_strlcpy(buf, "fr_FR", buflen); | ||
| 43 | break; | ||
| 44 | case PSP_SYSTEMPARAM_LANGUAGE_SPANISH: | ||
| 45 | SDL_strlcpy(buf, "es_ES", buflen); | ||
| 46 | break; | ||
| 47 | case PSP_SYSTEMPARAM_LANGUAGE_GERMAN: | ||
| 48 | SDL_strlcpy(buf, "de_DE", buflen); | ||
| 49 | break; | ||
| 50 | case PSP_SYSTEMPARAM_LANGUAGE_ITALIAN: | ||
| 51 | SDL_strlcpy(buf, "it_IT", buflen); | ||
| 52 | break; | ||
| 53 | case PSP_SYSTEMPARAM_LANGUAGE_DUTCH: | ||
| 54 | SDL_strlcpy(buf, "nl_NL", buflen); | ||
| 55 | break; | ||
| 56 | case PSP_SYSTEMPARAM_LANGUAGE_PORTUGUESE: | ||
| 57 | SDL_strlcpy(buf, "pt_PT", buflen); | ||
| 58 | break; | ||
| 59 | case PSP_SYSTEMPARAM_LANGUAGE_RUSSIAN: | ||
| 60 | SDL_strlcpy(buf, "ru_RU", buflen); | ||
| 61 | break; | ||
| 62 | case PSP_SYSTEMPARAM_LANGUAGE_KOREAN: | ||
| 63 | SDL_strlcpy(buf, "ko_KR", buflen); | ||
| 64 | break; | ||
| 65 | case PSP_SYSTEMPARAM_LANGUAGE_CHINESE_TRADITIONAL: | ||
| 66 | SDL_strlcpy(buf, "zh_TW", buflen); | ||
| 67 | break; | ||
| 68 | case PSP_SYSTEMPARAM_LANGUAGE_CHINESE_SIMPLIFIED: | ||
| 69 | SDL_strlcpy(buf, "zh_CN", buflen); | ||
| 70 | break; | ||
| 71 | default: | ||
| 72 | SDL_strlcpy(buf, "en_US", buflen); | ||
| 73 | break; | ||
| 74 | } | ||
| 75 | return true; | ||
| 76 | } | ||
| 77 | |||
| 78 | /* 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 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "SDL_internal.h" | ||
| 23 | #include "../SDL_syslocale.h" | ||
| 24 | |||
| 25 | static void normalize_locale_str(char *dst, char *str, size_t buflen) | ||
| 26 | { | ||
| 27 | char *ptr; | ||
| 28 | |||
| 29 | ptr = SDL_strchr(str, '.'); // chop off encoding if specified. | ||
| 30 | if (ptr) { | ||
| 31 | *ptr = '\0'; | ||
| 32 | } | ||
| 33 | |||
| 34 | ptr = SDL_strchr(str, '@'); // chop off extra bits if specified. | ||
| 35 | if (ptr) { | ||
| 36 | *ptr = '\0'; | ||
| 37 | } | ||
| 38 | |||
| 39 | // The "C" locale isn't useful for our needs, ignore it if you see it. | ||
| 40 | if ((str[0] == 'C') && (str[1] == '\0')) { | ||
| 41 | return; | ||
| 42 | } | ||
| 43 | |||
| 44 | if (*str) { | ||
| 45 | if (*dst) { | ||
| 46 | SDL_strlcat(dst, ",", buflen); // SDL has these split by commas | ||
| 47 | } | ||
| 48 | SDL_strlcat(dst, str, buflen); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | static void normalize_locales(char *dst, char *src, size_t buflen) | ||
| 53 | { | ||
| 54 | char *ptr; | ||
| 55 | |||
| 56 | // entries are separated by colons | ||
| 57 | while ((ptr = SDL_strchr(src, ':')) != NULL) { | ||
| 58 | *ptr = '\0'; | ||
| 59 | normalize_locale_str(dst, src, buflen); | ||
| 60 | src = ptr + 1; | ||
| 61 | } | ||
| 62 | normalize_locale_str(dst, src, buflen); | ||
| 63 | } | ||
| 64 | |||
| 65 | bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) | ||
| 66 | { | ||
| 67 | // !!! FIXME: should we be using setlocale()? Or some D-Bus thing? | ||
| 68 | bool isstack; | ||
| 69 | const char *envr; | ||
| 70 | char *tmp; | ||
| 71 | |||
| 72 | SDL_assert(buflen > 0); | ||
| 73 | tmp = SDL_small_alloc(char, buflen, &isstack); | ||
| 74 | if (!tmp) { | ||
| 75 | return false; | ||
| 76 | } | ||
| 77 | |||
| 78 | *tmp = '\0'; | ||
| 79 | |||
| 80 | // LANG is the primary locale (maybe) | ||
| 81 | envr = SDL_getenv("LANG"); | ||
| 82 | if (envr) { | ||
| 83 | SDL_strlcpy(tmp, envr, buflen); | ||
| 84 | } | ||
| 85 | |||
| 86 | // fallback languages | ||
| 87 | envr = SDL_getenv("LANGUAGE"); | ||
| 88 | if (envr) { | ||
| 89 | if (*tmp) { | ||
| 90 | SDL_strlcat(tmp, ":", buflen); | ||
| 91 | } | ||
| 92 | SDL_strlcat(tmp, envr, buflen); | ||
| 93 | } | ||
| 94 | |||
| 95 | if (*tmp == '\0') { | ||
| 96 | SDL_SetError("LANG environment variable isn't set"); | ||
| 97 | } else { | ||
| 98 | normalize_locales(buf, tmp, buflen); | ||
| 99 | } | ||
| 100 | |||
| 101 | SDL_small_free(tmp, isstack); | ||
| 102 | return true; | ||
| 103 | } | ||
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 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "SDL_internal.h" | ||
| 23 | #include "../SDL_syslocale.h" | ||
| 24 | |||
| 25 | #include <psp2/apputil.h> | ||
| 26 | #include <psp2/system_param.h> | ||
| 27 | |||
| 28 | bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) | ||
| 29 | { | ||
| 30 | const char *vita_locales[] = { | ||
| 31 | "ja_JP", | ||
| 32 | "en_US", | ||
| 33 | "fr_FR", | ||
| 34 | "es_ES", | ||
| 35 | "de_DE", | ||
| 36 | "it_IT", | ||
| 37 | "nl_NL", | ||
| 38 | "pt_PT", | ||
| 39 | "ru_RU", | ||
| 40 | "ko_KR", | ||
| 41 | "zh_TW", | ||
| 42 | "zh_CN", | ||
| 43 | "fi_FI", | ||
| 44 | "sv_SE", | ||
| 45 | "da_DK", | ||
| 46 | "no_NO", | ||
| 47 | "pl_PL", | ||
| 48 | "pt_BR", | ||
| 49 | "en_GB", | ||
| 50 | "tr_TR", | ||
| 51 | }; | ||
| 52 | |||
| 53 | Sint32 language = SCE_SYSTEM_PARAM_LANG_ENGLISH_US; | ||
| 54 | SceAppUtilInitParam initParam; | ||
| 55 | SceAppUtilBootParam bootParam; | ||
| 56 | SDL_zero(initParam); | ||
| 57 | SDL_zero(bootParam); | ||
| 58 | sceAppUtilInit(&initParam, &bootParam); | ||
| 59 | sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_LANG, &language); | ||
| 60 | |||
| 61 | if (language < 0 || language > SCE_SYSTEM_PARAM_LANG_TURKISH) { | ||
| 62 | language = SCE_SYSTEM_PARAM_LANG_ENGLISH_US; // default to english | ||
| 63 | } | ||
| 64 | |||
| 65 | SDL_strlcpy(buf, vita_locales[language], buflen); | ||
| 66 | |||
| 67 | sceAppUtilShutdown(); | ||
| 68 | return true; | ||
| 69 | } | ||
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 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "SDL_internal.h" | ||
| 23 | #include "../../core/windows/SDL_windows.h" | ||
| 24 | #include "../SDL_syslocale.h" | ||
| 25 | |||
| 26 | typedef BOOL(WINAPI *pfnGetUserPreferredUILanguages)(DWORD, PULONG, WCHAR *, PULONG); | ||
| 27 | #ifndef MUI_LANGUAGE_NAME | ||
| 28 | #define MUI_LANGUAGE_NAME 0x8 | ||
| 29 | #endif | ||
| 30 | |||
| 31 | static pfnGetUserPreferredUILanguages pGetUserPreferredUILanguages = NULL; | ||
| 32 | static HMODULE kernel32 = 0; | ||
| 33 | |||
| 34 | // this is the fallback for WinXP...one language, not a list. | ||
| 35 | static bool SDL_SYS_GetPreferredLocales_winxp(char *buf, size_t buflen) | ||
| 36 | { | ||
| 37 | char lang[16]; | ||
| 38 | char country[16]; | ||
| 39 | |||
| 40 | const int langrc = GetLocaleInfoA(LOCALE_USER_DEFAULT, | ||
| 41 | LOCALE_SISO639LANGNAME, | ||
| 42 | lang, sizeof(lang)); | ||
| 43 | |||
| 44 | const int ctryrc = GetLocaleInfoA(LOCALE_USER_DEFAULT, | ||
| 45 | LOCALE_SISO3166CTRYNAME, | ||
| 46 | country, sizeof(country)); | ||
| 47 | |||
| 48 | /* Win95 systems will fail, because they don't have LOCALE_SISO*NAME ... */ | ||
| 49 | if (langrc == 0) { | ||
| 50 | return SDL_SetError("Couldn't obtain language info"); | ||
| 51 | } else { | ||
| 52 | (void)SDL_snprintf(buf, buflen, "%s%s%s", lang, ctryrc ? "_" : "", ctryrc ? country : ""); | ||
| 53 | return true; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | // this works on Windows Vista and later. | ||
| 58 | static bool SDL_SYS_GetPreferredLocales_vista(char *buf, size_t buflen) | ||
| 59 | { | ||
| 60 | ULONG numlangs = 0; | ||
| 61 | WCHAR *wbuf = NULL; | ||
| 62 | ULONG wbuflen = 0; | ||
| 63 | bool isstack; | ||
| 64 | |||
| 65 | SDL_assert(pGetUserPreferredUILanguages != NULL); | ||
| 66 | pGetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numlangs, NULL, &wbuflen); | ||
| 67 | |||
| 68 | wbuf = SDL_small_alloc(WCHAR, wbuflen, &isstack); | ||
| 69 | if (!wbuf) { | ||
| 70 | return false; | ||
| 71 | } | ||
| 72 | |||
| 73 | if (!pGetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numlangs, wbuf, &wbuflen)) { | ||
| 74 | SDL_SYS_GetPreferredLocales_winxp(buf, buflen); // oh well, try the fallback. | ||
| 75 | } else { | ||
| 76 | const ULONG endidx = (ULONG)SDL_min(buflen, wbuflen - 1); | ||
| 77 | ULONG str_start = 0; | ||
| 78 | ULONG i; | ||
| 79 | for (i = 0; i < endidx; i++) { | ||
| 80 | const char ch = (char)wbuf[i]; // these should all be low-ASCII, safe to cast | ||
| 81 | if (ch == '\0') { | ||
| 82 | buf[i] = ','; // change null separators to commas | ||
| 83 | str_start = i; | ||
| 84 | } else if (ch == '-') { | ||
| 85 | buf[i] = '_'; // change '-' to '_' | ||
| 86 | } else { | ||
| 87 | buf[i] = ch; // copy through as-is. | ||
| 88 | } | ||
| 89 | } | ||
| 90 | buf[str_start] = '\0'; // terminate string, chop off final ',' | ||
| 91 | } | ||
| 92 | |||
| 93 | SDL_small_free(wbuf, isstack); | ||
| 94 | return true; | ||
| 95 | } | ||
| 96 | |||
| 97 | bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) | ||
| 98 | { | ||
| 99 | if (!kernel32) { | ||
| 100 | kernel32 = GetModuleHandle(TEXT("kernel32.dll")); | ||
| 101 | if (kernel32) { | ||
| 102 | pGetUserPreferredUILanguages = (pfnGetUserPreferredUILanguages)GetProcAddress(kernel32, "GetUserPreferredUILanguages"); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | if (!pGetUserPreferredUILanguages) { | ||
| 107 | return SDL_SYS_GetPreferredLocales_winxp(buf, buflen); // this is always available | ||
| 108 | } else { | ||
| 109 | return SDL_SYS_GetPreferredLocales_vista(buf, buflen); // available on Vista and later. | ||
| 110 | } | ||
| 111 | } | ||
