Get system language locale?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
GVovkiv
Party member
Posts: 678
Joined: Fri Jan 15, 2021 7:29 am

Get system language locale?

Post 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.
User avatar
marclurr
Party member
Posts: 111
Joined: Fri Apr 22, 2022 9:25 am

Re: Get system language locale?

Post by marclurr »

User avatar
GVovkiv
Party member
Posts: 678
Joined: Fri Jan 15, 2021 7:29 am

Re: Get system language locale?

Post by GVovkiv »

marclurr wrote: Sat Aug 19, 2023 4:24 pm This might help viewtopic.php?p=212987#p212987
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.
User avatar
marclurr
Party member
Posts: 111
Joined: Fri Apr 22, 2022 9:25 am

Re: Get system language locale?

Post 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. :\
User avatar
BrotSagtMist
Party member
Posts: 636
Joined: Fri Aug 06, 2021 10:30 pm

Re: Get system language locale?

Post 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.
obey
User avatar
GVovkiv
Party member
Posts: 678
Joined: Fri Jan 15, 2021 7:29 am

Re: Get system language locale?

Post 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.
User avatar
BrotSagtMist
Party member
Posts: 636
Joined: Fri Aug 06, 2021 10:30 pm

Re: Get system language locale?

Post 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?
obey
User avatar
GVovkiv
Party member
Posts: 678
Joined: Fri Jan 15, 2021 7:29 am

Re: Get system language locale?

Post 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?
User avatar
slime
Solid Snayke
Posts: 3144
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Get system language locale?

Post 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.
User avatar
BrotSagtMist
Party member
Posts: 636
Joined: Fri Aug 06, 2021 10:30 pm

Re: Get system language locale?

Post 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.
obey
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests