Page 1 of 2
Get system language locale?
Posted: Sat Aug 19, 2023 9:44 am
by GVovkiv
Is there any library or way to get system's current language code?
For example, if system uses some English variant, it would return "en" or "uk" if system in Ukrainian.
I know that there several codes standards and almost all OSs uses different one, but something unified and cross-platform would be fine by me.
Re: Get system language locale?
Posted: Sat Aug 19, 2023 4:24 pm
by marclurr
Re: Get system language locale?
Posted: Sat Aug 19, 2023 6:43 pm
by GVovkiv
Well, it kinda helps and not. Flatpak love it returns just "C" which is not really helpful information, and, apparently, on different OSs it will return different locale standards (which is not good) and also I somehow need to parse everything that this function might return.
Re: Get system language locale?
Posted: Sat Aug 19, 2023 7:48 pm
by marclurr
Ah yeah I hadn't run it until just now as I was on my phone. It returns "C" on my machine as well, that's a bit naff. You could always go with the other suggestion in that post and just allow the user to select their language manually, which is also a slightly mucky compromise. :\
Re: Get system language locale?
Posted: Sat Aug 19, 2023 8:12 pm
by BrotSagtMist
You can use getenv instead
But honestly this makes no sense, what information do you even want to obtain?
Cause there is no such thing as a set language.
We have timezone, time format, keyboard, spell check and so on, and noone of them have to even match.
I mean my timezone is german, my language is english and my keyboard is of the charts.
Re: Get system language locale?
Posted: Sun Aug 20, 2023 10:58 am
by GVovkiv
marclurr wrote: ↑Sat Aug 19, 2023 7:48 pm
Ah yeah I hadn't run it until just now as I was on my phone. It returns "C" on my machine as well, that's a bit naff. You could always go with the other suggestion in that post and just allow the user to select their language manually, which is also a slightly mucky compromise. :\
Yes, I can and would, probably, do that in future
BrotSagtMist wrote: ↑Sat Aug 19, 2023 8:12 pm
You can use getenv instead
But honestly this makes no sense, what information do you even want to obtain?
Cause there is no such thing as a set language.
We have timezone, time format, keyboard, spell check and so on, and noone of them have to even match.
I mean my timezone is german, my language is english and my keyboard is of the charts.
Well, I would pick language in-game (if game supports one) based on that information. (Even if I would use suggestion from link about "choose your language on 1st run", I still want to highlight language option that match system language.) While some people definitely doesn't want to use/pick language in-game that based on system language, majority will, so this small feature is definitely handy.
For example, in Godot, there exists and fully works such system. No matter on which system you run game, Godot will convert that information to same standard (like en_US or uk_UA), which is definitely handy to have.
Cause there is no such thing as a set language.
Considering that engines such as Unity or Godot can provide such information, or even some software frameworks/tools such as GTK or Qt and do that in cross-platform manner, I think this is definitely possible.
You can use getenv instead
Yes, but this would require me to parse and process this information on different OSs that do that in different manner (for example, linux returns data in "uk_UA" manner, while windows use different ISO, macOS probably too, and maybe even android) and then convert all of this to 1 standard which I would later use in-game (because if in-game I would identify "en_US" and windows would return something in windows specific format "KZ-1048", then it's not going to work). I don't think I have required knowledge to do so, nor do power to maintain this thing. Because such feature should be done in scope of some library rather then game code hack.
Re: Get system language locale?
Posted: Sun Aug 20, 2023 11:29 am
by BrotSagtMist
But again, Language of what?
What actually is the output of unity and godot based on?
If i print my system environment i get a whooping 11 results, i can only identify 3 as useful.
The system language, the spellcheck, the date.
My system is en_US, my spellcheck is en_GB and my date is de_DE.
So which language you want to give me?
Re: Get system language locale?
Posted: Sun Aug 20, 2023 12:32 pm
by GVovkiv
BrotSagtMist wrote: ↑Sun Aug 20, 2023 11:29 am
But again, Language of what?
What actually is the output of unity and godot based on?
If i print my system environment i get a whooping 11 results, i can only identify 3 as useful.
The system language, the spellcheck, the date.
My system is en_US, my spellcheck is en_GB and my date is de_DE.
So which language you want to give me?
Your system language? Why should it something else?
Re: Get system language locale?
Posted: Sun Aug 20, 2023 1:34 pm
by slime
love 12 has a
love.system.getPreferredLocales function.
However, if your game is on Steam you should use Steam's APIs instead. They let users choose a per-game preferred locale inside Steam that's separate from OS settings.
Re: Get system language locale?
Posted: Sun Aug 20, 2023 2:06 pm
by BrotSagtMist
Yee i forgot what my chain of thought was leading to.
There was something, but i havent slept in like 30 hours and it takes its toll.