touchHLE icon indicating copy to clipboard operation
touchHLE copied to clipboard

Language/locale detection doesn't work on Windows (falls back to English)

Open hikari-no-yume opened this issue 2 years ago • 1 comments

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.

hikari-no-yume avatar Feb 04 '23 11:02 hikari-no-yume

I added a note about it to the README now.

hikari-no-yume avatar Feb 04 '23 12:02 hikari-no-yume

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
}

migueletto avatar Feb 19 '23 23:02 migueletto

Ah, the same problem exists on Android too. I should really fix this for the next release.

hikari-no-yume avatar Sep 01 '23 09:09 hikari-no-yume

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!

hikari-no-yume avatar Oct 25 '23 16:10 hikari-no-yume