Select language automatically, based on system settings

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Select language automatically, based on system settings

#16 Post by PyTom »

It's pretty easy to detect the platform you're running on, and make the code conditional. You can use the renpy.windows, renpy.macintosh, and renpy.linux variables to detect the platform and decide.

That being said, if someone has a faulty locale, it's probably okay to default to it. I'm guessing they're used to this sort of problem, especially if you make the language change menu accessible to them.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Lobo Demente
Newbie
Posts: 14
Joined: Wed Nov 14, 2012 7:37 am
Contact:

Re: Select language automatically, based on system settings

#17 Post by Lobo Demente »

Well, I think I've found a solution to all this bitter arguing, and I think it's the better one for us all as it doesn't involve any system-specific programming (I myself find it a nasty way of writting a program when there's an alternative, for example, I wouldn't like to be forced to learn about any MacOS APIS just to allow a game to be run in all platforms when it should do without any specific code, as Ren'Py does), and neither it needs a multilingual player to fiddle with advanced settings more than once. The ultimate reason is that this method I'm going to explain is the intended way of using a multi-user OS.

The trick is to create another user account (named "JPlayer" for example, but that doesn't matter at all) and set its locales to the specific ones the desired game needs or whatever other configuration that should make our system lie :) . You can even set its timezone to japan, use their date/time formats or change the keyboard mapping in order to use a physical japanese keyboard, and neither of these changes will affect the main user account.

Everytime a player needs its computer using japanese locales, he or she must just run the game with that JPlayer credentials logging off and on again. Even better, under Windows7 it works too when using right-click and "run as..." option (so the user doesn't need to close the active session and log on again), so I assume it will work with Vista too, but the account needs to be password protected then. I haven't tested it yet with XP, where I don't know if locales can be set on a per-user basis.

Another nice side effects of this way of using Windows are:
- You can even encrypt some folders just for that user, so nobody else could know if you're playing any real nasty hentai games :mrgreen:
- You can keep your own savegames, so if you share your computer with anyone else, just create a new user for him/her and nobody will be allowed to "accidentally" finish, delete or overwrite your game.
- If you do write Ren'Py games too, your code will be simpler and nicer to keep and understand.

I guess we can become friends again now :wink:

AxemRed
Veteran
Posts: 482
Joined: Sun Jan 09, 2011 7:10 am
Contact:

Re: Select language automatically, based on system settings

#18 Post by AxemRed »

Wow, that's an impressively awful solution. For one, it doesn't actually solve the problem of the locale's language being unreliable on Windows. Second, it's ludicrously convoluted compared to just running the offending app in a different locale with AppLocale/NTLEA. Third, it's a complex multi-step technical solution for a problem primarily experienced by people lacking the capabilities or knowledge to execute just such a solution or they'd be using AppLocale in the first place.

You cannot trust the locale's language on Windows systems.

User avatar
Lobo Demente
Newbie
Posts: 14
Joined: Wed Nov 14, 2012 7:37 am
Contact:

Re: Select language automatically, based on system settings

#19 Post by Lobo Demente »

AxemRed wrote:You cannot trust the locale's language on Windows systems.
You cannot trust your time clock neither, then.

And sure it's easier using some weird application than using your system in the way it's meant to be used. It's a lot easier for that people without technical knowledge to fiddle with advanced settings... yes.

AxemRed
Veteran
Posts: 482
Joined: Sun Jan 09, 2011 7:10 am
Contact:

Re: Select language automatically, based on system settings

#20 Post by AxemRed »

Indeed, the clock can be wrong as well. That's irrelevant to this discussion.

AppLocale is a Microsoft tool specifically created to run applications incompatible with the current locale. I consider that more 'the way it's meant to be used' than some elaborate multi-account setup.

Regardless, POSIX locale is still an unreliable way of detecting the user's preferred language on Windows. Use the Windows API, it actually works.

User avatar
Lobo Demente
Newbie
Posts: 14
Joined: Wed Nov 14, 2012 7:37 am
Contact:

Re: Select language automatically, based on system settings

#21 Post by Lobo Demente »

AxemRed wrote:Indeed, the clock can be wrong as well. That's irrelevant to this discussion.
It's not irrelevant. If I can't trust locales because the user can change them at his/her will, any other setting that's susceptible to be changed by the user is as unreliable as locales. So I'll have to make my programs with every possible devious use in mind in order to make it work under every esoteric situation a user can create. Great.
AxemRed wrote:AppLocale is a Microsoft tool specifically created to run...
...under Windows XP/2003 Server only, yes: http://www.microsoft.com/en-us/download ... x?id=13209 . I find it quite funny since the API you told me to use requires Vista as the minimum client version.
AxemRed wrote:Use the Windows API, it actually works.
I'm sure it works, I'll never going to say otherwise. I know how APIs work and know a bunch of them as I make intensive use of them everyday when at work. But can you please explain to our readers how exactly I'm supposed to use a Microsoft Windows API under Linux or Apple's MacOS?

Or are you telling me that I must learn the MacOS core (wich I don't know and in wich I don't have any interest by now) to implement a functionality that's as simple as that? Please read carefully every single post in this thread since the very first one: the snippet just sets the initial language of the game instead of setting it to english by default, making an assumption on locales instead of setting the language to english by default. Yes, as simple as you read, "instead of setting the language to english by default".

If you don't want to, or can't, use your computer the standard way it's fine for me, but please stop boring me. Not sure, but I believe that you can create another thread in the forum with a snippet of your own that uses any API you like. It'll be fine for me even if it grows a fan club.

SO: I hereby allow you to not use my snippet at all or any games that could make use of it if you don't want to. It doesn't matter at all, really, it's fine, I won't bother you, trust me.

Thanks.

(Now you can get the last word if you feel like it. I probably won't agree with what you say, but I don't care neither. Thanks too. Be happy.)

AxemRed
Veteran
Posts: 482
Joined: Sun Jan 09, 2011 7:10 am
Contact:

Re: Select language automatically, based on system settings

#22 Post by AxemRed »

Lobo Demente wrote:If I can't trust locales because the user can change them at his/her will, ...
No, you can't trust locales on Windows because they often do not reflect the user's preferred language either through technical necessity or accident. Changing the locale requires uncommon technical knowledge and a reboot.
Lobo Demente wrote:
AxemRed wrote:AppLocale is a Microsoft tool specifically created to run...
...under Windows XP/2003 Server only, yes: http://www.microsoft.com/en-us/download ... x?id=13209 . I find it quite funny since the API you told me to use requires Vista as the minimum client version.
I'm running it under Win7 x64 right now. There's GetUserDefaultUILanguage if you want to support legacy versions of Windows (WinME+).
Lobo Demente wrote:
AxemRed wrote:Use the Windows API, it actually works.
I'm sure it works, I'll never going to say otherwise. I know how APIs work and know a bunch of them as I make intensive use of them everyday when at work. But can you please explain to our readers how exactly I'm supposed to use a Microsoft Windows API under Linux or Apple's MacOS?
You use the POSIX API, except on Windows where you should attempt to use the Windows API because the POSIX one is broken.

I only said it was broken. You're the one who keeps coming up with progressively sillier reasons why you shouldn't have to fix it. You could've just told the truth -- that you couldn't be bothered -- and left it at that.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Select language automatically, based on system settings

#23 Post by PyTom »

At this point, this thread is providing more heat than light. Locking it.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Locked

Who is online

Users browsing this forum: No registered users