Proposal: SDL_PreferredLocales()

Fwiw I like this approach as well!
Vittorio
PS 1USD per use? Is that FRAND? ;)On Mon, Oct 22, 2012 at 9:53 PM, Gabriel Jacobo wrote:

2012/10/22 Tim Angus

On 22/10/2012 14:11, Alex Barry wrote:

One suggestion I liked (but I can’t seem to find) is having the two
pieces of information separated, so rather than:

extern DECLSPEC const char ** SDLCALL SDL_PreferredLocales(void);

It could be something like:

typedef struct {
   const char *language;
   const char *region;
} SDL_Locale;

extern DECLSPEC const SDL_Locale* SDLCALL SDL_PreferredLocales(void);

Agreed.

I suggested that, it seems easier to work with, specially if we allow
region/country to be null. You can use this suggestion freely as long as I
get a royalty of 1 USD per use :slight_smile:


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I know the question is addressed to Ryan, but I may be able to clarify how
I’d approach that sort of situation. I’d have an in-app list of all
supported languages, and when the app starts, it finds the closest matched
based on the settings from SDL_PreferredLocales(), and that’s how the
application would launch. Then, inside the application, the user could
change the locale setting, the application reloads it’s assets (and
possibly sends some sort of OS-level call to change the keyboard layout?),
and the user is set to go.On Mon, Oct 22, 2012 at 5:23 PM, Dave wrote:

On Sun, 21 Oct 2012, Ryan C. Gordon wrote:

I actually think my objection is completely ridiculous (incidentally,

I like the api, particularly it’s simplicity), but I’ll say it
anyways: what if the user CHANGES their locale settings while a
program is running?

Can you think of a realistic situation where someone says “it’s my turn
to play this game in a foreign language, so I’m going to change a setting
in the system control panel and not restart the app”?

Ryan,

I do know of one case where I’ve seen this first hand. My wife is from
Quebec and she is constantly switching back and forth between locales for
keyboard layout – so that she can google something in English or French as
desired, for example.

One could imagine that this might come into play for in-game chat
functionality. Of course, in order to be useful this hypothetical chat
would also need to be able to switch locales as well, and that is beyond
the scope of what you’re proposing. But, I wanted to throw this experience
out there in case it is useful.

Dave

_____________**
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/**listinfo.cgi/sdl-libsdl.orghttp://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Keyboard layout is not the same thing as locale. I certainly don’t want
my programs to suddenly change language just because I need to switch to
input a few Japanese characters using a Japanese keyboard layout.On 2012-10-22 23:23, Dave wrote:

On Sun, 21 Oct 2012, Ryan C. Gordon wrote:

Can you think of a realistic situation where someone says “it’s my
turn to play this game in a foreign language, so I’m going to change a
setting in the system control panel and not restart the app”?

I do know of one case where I’ve seen this first hand. My wife is from
Quebec and she is constantly switching back and forth between locales
for keyboard layout – so that she can google something in English or
French as desired, for example.


Rainer Deyke (rainerd at eldwood.com)

@icculus This would come in handy. Right now the only platform-specific code we use in our game is for retrieving the current system language. I was searching for a function in SDL2 that would do this but there wasn’t any.

In case anyone cares we currently use the following #ifdef'd functions:

Win32:

WORD lang = PRIMARYLANGID(GetUserDefaultUILanguage());

     if (lang == LANG_ENGLISH)             return EXAI::LANGUAGE_ENGLISH;     /* Default English (Same as US English) */
else if (lang == LANG_FRENCH)              return EXAI::LANGUAGE_FRENCH;      /* French */
else if (lang == LANG_RUSSIAN)             return EXAI::LANGUAGE_RUSSIAN;     /* Russian */
else if (lang == LANG_CHINESE_TRADITIONAL) return EXAI::LANGUAGE_TRADCHINESE; /* Traditional Chinese */

Linux:

char *lang = getenv("LANG"); if (!lang) goto exit;

     if (lang == strstr(lang, "en")   )    return EXAI::LANGUAGE_ENGLISH;     /* Default English (Same as US English) */
else if (lang == strstr(lang, "fr")   )    return EXAI::LANGUAGE_FRENCH;      /* French */
else if (lang == strstr(lang, "ru")   )    return EXAI::LANGUAGE_RUSSIAN;     /* Russian */
else if (lang == strstr(lang, "zh_TW"))    return EXAI::LANGUAGE_TRADCHINESE; /* Traditional Chinese */

macOS:

#include <CoreFoundation/CoreFoundation.h>

/* swy: probably the ugliest thing i have ever seen; Apple's CoreFoundation is
        going to win a prize for enterprise-y coding or something */
char lang[99] = {0}; CFStringGetCString((CFStringRef) CFLocaleGetValue(CFLocaleCopyCurrent(), kCFLocaleLanguageCode), lang, sizeof(lang), kCFStringEncodingUTF8);

     if (lang == strstr(lang, "en")     )  return EXAI::LANGUAGE_ENGLISH;     /* Default English (Same as US English) */
else if (lang == strstr(lang, "fr")     )  return EXAI::LANGUAGE_FRENCH;      /* French */
else if (lang == strstr(lang, "ru")     )  return EXAI::LANGUAGE_RUSSIAN;     /* Russian */
else if (lang == strstr(lang, "zh-Hant"))  return EXAI::LANGUAGE_TRADCHINESE; /* Traditional Chinese */

(Notice how there are many corner cases like the language code used for Traditional Chinese.)

Wrapping all this in an uniformly cross-platform function would be amazing!