Initial Commit
This commit is contained in:
112
thirdparty/SDL3-3.4.0/src/locale/SDL_locale.c
vendored
Normal file
112
thirdparty/SDL3-3.4.0/src/locale/SDL_locale.c
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 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, 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);
|
||||
}
|
||||
33
thirdparty/SDL3-3.4.0/src/locale/SDL_syslocale.h
vendored
Normal file
33
thirdparty/SDL3-3.4.0/src/locale/SDL_syslocale.h
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 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, 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
|
||||
29
thirdparty/SDL3-3.4.0/src/locale/android/SDL_syslocale.c
vendored
Normal file
29
thirdparty/SDL3-3.4.0/src/locale/android/SDL_syslocale.c
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 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, 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);
|
||||
}
|
||||
29
thirdparty/SDL3-3.4.0/src/locale/dummy/SDL_syslocale.c
vendored
Normal file
29
thirdparty/SDL3-3.4.0/src/locale/dummy/SDL_syslocale.c
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 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, 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();
|
||||
}
|
||||
71
thirdparty/SDL3-3.4.0/src/locale/emscripten/SDL_syslocale.c
vendored
Normal file
71
thirdparty/SDL3-3.4.0/src/locale/emscripten/SDL_syslocale.c
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 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, 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 <emscripten.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
72
thirdparty/SDL3-3.4.0/src/locale/haiku/SDL_syslocale.cc
vendored
Normal file
72
thirdparty/SDL3-3.4.0/src/locale/haiku/SDL_syslocale.cc
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 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, 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 <AppKit.h>
|
||||
#include <LocaleRoster.h>
|
||||
#include <TypeConstants.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
76
thirdparty/SDL3-3.4.0/src/locale/macos/SDL_syslocale.m
vendored
Normal file
76
thirdparty/SDL3-3.4.0/src/locale/macos/SDL_syslocale.m
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 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, 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 <Foundation/Foundation.h>
|
||||
|
||||
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;
|
||||
}
|
||||
55
thirdparty/SDL3-3.4.0/src/locale/n3ds/SDL_syslocale.c
vendored
Normal file
55
thirdparty/SDL3-3.4.0/src/locale/n3ds/SDL_syslocale.c
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 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, 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;
|
||||
}
|
||||
307
thirdparty/SDL3-3.4.0/src/locale/ngage/SDL_syslocale.cpp
vendored
Normal file
307
thirdparty/SDL3-3.4.0/src/locale/ngage/SDL_syslocale.cpp
vendored
Normal file
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 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, 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 <bautils.h>
|
||||
#include <e32base.h>
|
||||
#include <e32cons.h>
|
||||
#include <e32std.h>
|
||||
|
||||
bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
|
||||
{
|
||||
TLanguage language = User::Language();
|
||||
const char *locale;
|
||||
|
||||
switch (language) {
|
||||
case ELangFrench:
|
||||
case ELangSwissFrench:
|
||||
locale = "fr_CH";
|
||||
break;
|
||||
case ELangBelgianFrench:
|
||||
locale = "fr_BE";
|
||||
break;
|
||||
case ELangInternationalFrench:
|
||||
locale = "fr_FR";
|
||||
break;
|
||||
case ELangGerman:
|
||||
case ELangSwissGerman:
|
||||
case ELangAustrian:
|
||||
locale = "de_DE";
|
||||
break;
|
||||
case ELangSpanish:
|
||||
case ELangInternationalSpanish:
|
||||
case ELangLatinAmericanSpanish:
|
||||
locale = "es_ES";
|
||||
break;
|
||||
case ELangItalian:
|
||||
case ELangSwissItalian:
|
||||
locale = "it_IT";
|
||||
break;
|
||||
case ELangSwedish:
|
||||
case ELangFinlandSwedish:
|
||||
locale = "sv_SE";
|
||||
break;
|
||||
case ELangDanish:
|
||||
locale = "da_DK";
|
||||
break;
|
||||
case ELangNorwegian:
|
||||
case ELangNorwegianNynorsk:
|
||||
locale = "no_NO";
|
||||
break;
|
||||
case ELangFinnish:
|
||||
locale = "fi_FI";
|
||||
break;
|
||||
case ELangPortuguese:
|
||||
locale = "pt_PT";
|
||||
break;
|
||||
case ELangBrazilianPortuguese:
|
||||
locale = "pt_BR";
|
||||
break;
|
||||
case ELangTurkish:
|
||||
case ELangCyprusTurkish:
|
||||
locale = "tr_TR";
|
||||
break;
|
||||
case ELangIcelandic:
|
||||
locale = "is_IS";
|
||||
break;
|
||||
case ELangRussian:
|
||||
locale = "ru_RU";
|
||||
break;
|
||||
case ELangHungarian:
|
||||
locale = "hu_HU";
|
||||
break;
|
||||
case ELangDutch:
|
||||
locale = "nl_NL";
|
||||
break;
|
||||
case ELangBelgianFlemish:
|
||||
locale = "nl_BE";
|
||||
break;
|
||||
case ELangAustralian:
|
||||
case ELangNewZealand:
|
||||
locale = "en_AU";
|
||||
break;
|
||||
case ELangCzech:
|
||||
locale = "cs_CZ";
|
||||
break;
|
||||
case ELangSlovak:
|
||||
locale = "sk_SK";
|
||||
break;
|
||||
case ELangPolish:
|
||||
locale = "pl_PL";
|
||||
break;
|
||||
case ELangSlovenian:
|
||||
locale = "sl_SI";
|
||||
break;
|
||||
case ELangTaiwanChinese:
|
||||
locale = "zh_TW";
|
||||
break;
|
||||
case ELangHongKongChinese:
|
||||
locale = "zh_HK";
|
||||
break;
|
||||
case ELangPrcChinese:
|
||||
locale = "zh_CN";
|
||||
break;
|
||||
case ELangJapanese:
|
||||
locale = "ja_JP";
|
||||
break;
|
||||
case ELangThai:
|
||||
locale = "th_TH";
|
||||
break;
|
||||
case ELangAfrikaans:
|
||||
locale = "af_ZA";
|
||||
break;
|
||||
case ELangAlbanian:
|
||||
locale = "sq_AL";
|
||||
break;
|
||||
case ELangAmharic:
|
||||
locale = "am_ET";
|
||||
break;
|
||||
case ELangArabic:
|
||||
locale = "ar_SA";
|
||||
break;
|
||||
case ELangArmenian:
|
||||
locale = "hy_AM";
|
||||
break;
|
||||
case ELangAzerbaijani:
|
||||
locale = "az_AZ";
|
||||
break;
|
||||
case ELangBelarussian:
|
||||
locale = "be_BY";
|
||||
break;
|
||||
case ELangBengali:
|
||||
locale = "bn_IN";
|
||||
break;
|
||||
case ELangBulgarian:
|
||||
locale = "bg_BG";
|
||||
break;
|
||||
case ELangBurmese:
|
||||
locale = "my_MM";
|
||||
break;
|
||||
case ELangCatalan:
|
||||
locale = "ca_ES";
|
||||
break;
|
||||
case ELangCroatian:
|
||||
locale = "hr_HR";
|
||||
break;
|
||||
case ELangEstonian:
|
||||
locale = "et_EE";
|
||||
break;
|
||||
case ELangFarsi:
|
||||
locale = "fa_IR";
|
||||
break;
|
||||
case ELangCanadianFrench:
|
||||
locale = "fr_CA";
|
||||
break;
|
||||
case ELangScotsGaelic:
|
||||
locale = "gd_GB";
|
||||
break;
|
||||
case ELangGeorgian:
|
||||
locale = "ka_GE";
|
||||
break;
|
||||
case ELangGreek:
|
||||
case ELangCyprusGreek:
|
||||
locale = "el_GR";
|
||||
break;
|
||||
case ELangGujarati:
|
||||
locale = "gu_IN";
|
||||
break;
|
||||
case ELangHebrew:
|
||||
locale = "he_IL";
|
||||
break;
|
||||
case ELangHindi:
|
||||
locale = "hi_IN";
|
||||
break;
|
||||
case ELangIndonesian:
|
||||
locale = "id_ID";
|
||||
break;
|
||||
case ELangIrish:
|
||||
locale = "ga_IE";
|
||||
break;
|
||||
case ELangKannada:
|
||||
locale = "kn_IN";
|
||||
break;
|
||||
case ELangKazakh:
|
||||
locale = "kk_KZ";
|
||||
break;
|
||||
case ELangKhmer:
|
||||
locale = "km_KH";
|
||||
break;
|
||||
case ELangKorean:
|
||||
locale = "ko_KR";
|
||||
break;
|
||||
case ELangLao:
|
||||
locale = "lo_LA";
|
||||
break;
|
||||
case ELangLatvian:
|
||||
locale = "lv_LV";
|
||||
break;
|
||||
case ELangLithuanian:
|
||||
locale = "lt_LT";
|
||||
break;
|
||||
case ELangMacedonian:
|
||||
locale = "mk_MK";
|
||||
break;
|
||||
case ELangMalay:
|
||||
locale = "ms_MY";
|
||||
break;
|
||||
case ELangMalayalam:
|
||||
locale = "ml_IN";
|
||||
break;
|
||||
case ELangMarathi:
|
||||
locale = "mr_IN";
|
||||
break;
|
||||
case ELangMoldavian:
|
||||
locale = "ro_MD";
|
||||
break;
|
||||
case ELangMongolian:
|
||||
locale = "mn_MN";
|
||||
break;
|
||||
case ELangPunjabi:
|
||||
locale = "pa_IN";
|
||||
break;
|
||||
case ELangRomanian:
|
||||
locale = "ro_RO";
|
||||
break;
|
||||
case ELangSerbian:
|
||||
locale = "sr_RS";
|
||||
break;
|
||||
case ELangSinhalese:
|
||||
locale = "si_LK";
|
||||
break;
|
||||
case ELangSomali:
|
||||
locale = "so_SO";
|
||||
break;
|
||||
case ELangSwahili:
|
||||
locale = "sw_KE";
|
||||
break;
|
||||
case ELangTajik:
|
||||
locale = "tg_TJ";
|
||||
break;
|
||||
case ELangTamil:
|
||||
locale = "ta_IN";
|
||||
break;
|
||||
case ELangTelugu:
|
||||
locale = "te_IN";
|
||||
break;
|
||||
case ELangTibetan:
|
||||
locale = "bo_CN";
|
||||
break;
|
||||
case ELangTigrinya:
|
||||
locale = "ti_ET";
|
||||
break;
|
||||
case ELangTurkmen:
|
||||
locale = "tk_TM";
|
||||
break;
|
||||
case ELangUkrainian:
|
||||
locale = "uk_UA";
|
||||
break;
|
||||
case ELangUrdu:
|
||||
locale = "ur_PK";
|
||||
break;
|
||||
case ELangUzbek:
|
||||
locale = "uz_UZ";
|
||||
break;
|
||||
case ELangVietnamese:
|
||||
locale = "vi_VN";
|
||||
break;
|
||||
case ELangWelsh:
|
||||
locale = "cy_GB";
|
||||
break;
|
||||
case ELangZulu:
|
||||
locale = "zu_ZA";
|
||||
break;
|
||||
case ELangEnglish:
|
||||
locale = "en_GB";
|
||||
break;
|
||||
case ELangAmerican:
|
||||
case ELangCanadianEnglish:
|
||||
case ELangInternationalEnglish:
|
||||
case ELangSouthAfricanEnglish:
|
||||
default:
|
||||
locale = "en_US";
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_strlcpy(buf, locale, buflen);
|
||||
|
||||
return true;
|
||||
}
|
||||
78
thirdparty/SDL3-3.4.0/src/locale/psp/SDL_syslocale.c
vendored
Normal file
78
thirdparty/SDL3-3.4.0/src/locale/psp/SDL_syslocale.c
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 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, 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 <psputility.h>
|
||||
|
||||
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: */
|
||||
103
thirdparty/SDL3-3.4.0/src/locale/unix/SDL_syslocale.c
vendored
Normal file
103
thirdparty/SDL3-3.4.0/src/locale/unix/SDL_syslocale.c
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 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, 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;
|
||||
}
|
||||
69
thirdparty/SDL3-3.4.0/src/locale/vita/SDL_syslocale.c
vendored
Normal file
69
thirdparty/SDL3-3.4.0/src/locale/vita/SDL_syslocale.c
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 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, 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 <psp2/apputil.h>
|
||||
#include <psp2/system_param.h>
|
||||
|
||||
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;
|
||||
}
|
||||
111
thirdparty/SDL3-3.4.0/src/locale/windows/SDL_syslocale.c
vendored
Normal file
111
thirdparty/SDL3-3.4.0/src/locale/windows/SDL_syslocale.c
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 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, 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.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user