mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 08:44:19 -04:00
Implement user preferred language detection on Mac
This commit is contained in:
parent
d63110a49e
commit
58963a167c
@ -42,8 +42,51 @@
|
||||
#define snprintf sprintf_s
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
static LanguageIndex li = LI_default;
|
||||
|
||||
#ifdef __APPLE__
|
||||
static LanguageIndex detect_language() {
|
||||
// Get and iterate through the list of preferred languages.
|
||||
CFArrayRef langs = CFLocaleCopyPreferredLanguages();
|
||||
CFIndex num_langs = CFArrayGetCount(langs);
|
||||
|
||||
for (long i = 0; i < num_langs; ++i) {
|
||||
CFStringRef lang = (CFStringRef)CFArrayGetValueAtIndex(langs, i);
|
||||
|
||||
CFIndex length = CFStringGetLength(lang);
|
||||
if (length < 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CFIndex max_size = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
|
||||
char *buffer = (char *)alloca(max_size);
|
||||
if (!CFStringGetCString(lang, buffer, max_size, kCFStringEncodingUTF8)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isalnum(buffer[2])) {
|
||||
// It's not a two-letter code.
|
||||
continue;
|
||||
}
|
||||
|
||||
// See if we support this language.
|
||||
for (int j = 0; j < LI_COUNT; ++j) {
|
||||
const char *lang_code = language_codes[j];
|
||||
if (lang_code != NULL && strncasecmp(buffer, lang_code, 2) == 0) {
|
||||
CFRelease(langs);
|
||||
return (LanguageIndex)j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(langs);
|
||||
return LI_default;
|
||||
}
|
||||
#else
|
||||
static LanguageIndex detect_language() {
|
||||
// First consult the LANGUAGE variable, which is a GNU extension that can
|
||||
// contain multiple languages in order of preference.
|
||||
@ -94,6 +137,7 @@ static LanguageIndex detect_language() {
|
||||
}
|
||||
return LI_default;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
int WINAPI
|
||||
@ -153,7 +197,7 @@ AuthDialog(const wstring &cert_filename, const wstring &cert_dir) :
|
||||
AuthDialog::
|
||||
AuthDialog(const string &cert_filename, const string &cert_dir) :
|
||||
#endif
|
||||
Fl_Window(435, 242, "New Panda3D Application"),
|
||||
Fl_Window(435, 242, new_application_title[li]),
|
||||
_cert_dir(cert_dir)
|
||||
{
|
||||
_view_cert_dialog = NULL;
|
||||
|
@ -323,8 +323,9 @@ verified_cert_text[LI_COUNT] = {
|
||||
// epo
|
||||
"\304\210i tiu aplika\304\265o estas subskribita de %s. "
|
||||
"Se %s estas fidinda la\305\255 vi, premu la butonon 'Lan\304\211i' sube por "
|
||||
"lan\304\211i \304\211i tiun aplika\304\265on per via komputilo. Anka\305\255 tio a\305\255tomate estonece "
|
||||
"aprobos \304\211i tiun kaj alian ajn aplika\304\265on, kiu estas subskribita de %s.\n"
|
||||
"lan\304\211i \304\211i tiun aplika\304\265on per via komputilo. Anka\305\255 "
|
||||
"tio a\305\255tomate estonece aprobos \304\211i tiun kaj alian ajn "
|
||||
"aplika\304\265on, kiu estas subskribita de %s.\n"
|
||||
"\n"
|
||||
"Se vi ne estas certa pri \304\211i tiu aplika\304\265o, "
|
||||
"vi anstata\305\255e povus premi la butonon 'Nuligi'.",
|
||||
@ -546,7 +547,7 @@ no_cert_text[LI_COUNT] = {
|
||||
|
||||
// epo
|
||||
"\304\210i tiu aplika\304\265o de Panda3D ne estas subskribita. Tio "
|
||||
"signifas ke vi ne havas certan scimanieron pri la vera verkanto de "
|
||||
"signifas ke vi ne havas certan scimanieron pri la vera verkanto de "
|
||||
"la aplika\304\265o.\n"
|
||||
"\n"
|
||||
"Premu la butonon 'Nuligi' por eviti lan\304\211on de \304\211i tiu "
|
||||
|
Loading…
x
Reference in New Issue
Block a user