Implement user preferred language detection on Mac

This commit is contained in:
rdb 2015-09-11 15:43:22 +02:00
parent d63110a49e
commit 58963a167c
2 changed files with 49 additions and 4 deletions

View File

@ -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;

View File

@ -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 "