touchHLE
touchHLE copied to clipboard
Language/locale detection doesn't work on Windows (falls back to English)
Super Monkey Ball requests the language via NSLocale
and I wrote a simple implementation that checks your LANG
environment variable and reports the language part (en
, ja
, etc). That works on macOS and (based on a video I've seen) presumably Linux. Windows doesn't set that variable though, so we just report en
instead, which isn't very accessible.
I'm not sure what the best way to check the user's language preference is on Windows. I know there's a registry key for it, but I don't know if that's the correct approach, and we'd need a table to convert Microsoft language codes into the ISO 639-1 code.
It would be especially nice if we could actually get a list of all languages the user wants, since NSLocale
supports that. The LANG
variable doesn't have that info, so currently we don't support that on any platform.
I added a note about it to the README now.
When using Win32 API in C, you have GetUserDefaultLCID. There are some caveats when using it, but it has worked for me. It can be used like this:
char buf[16];
LCID lcid = GetUserDefaultLCID();
if (GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME, buf, sizeof(buf))) {
// buf contains a 2 letter country code
} else if (GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME2, buf, sizeof(buf))) {
// buf contains a 3 letter country code
}
Ah, the same problem exists on Android too. I should really fix this for the next release.
Ah, it turns out there is a function for this in SDL2, and I'd missed it because Rust-SDL2 doesn't have a safe Rust wrapper for it. So, I don't need to do any platform-specific stuff, I can let SDL2 do all the work for me: db6f5d088ab8676907fe5b0baf4a887d34d65b8f.
This will be in touchHLE v0.2.1, sorry for the long wait!