Run your script under specific UI languages

Put simple Tips and Tricks that are not entire Tutorials in this forum
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Run your script under specific UI languages

08 Sep 2019, 19:42

If your system language is not English, but wanted to provide the English error messages in your post, what would you do?

I usally do is to change the system language to English and restart my computer..
Recently I found a software Locale Emulator can solve the problem perfectly.

Or you can use SetThreadUILanguage function:

Code: Select all

DllCall("SetThreadUILanguage", "ushort", 0x0409, "ushort") ; US = 0x0409
ComObjCreate("error test")
Note: In order to use the LangId in SetThreadUILanguage, the language needs to be installed (except for English), and a reboot is required.
Links: Language Identifier Constants and Strings
Last edited by tmplinshi on 10 Sep 2019, 05:14, edited 2 times in total.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Run your script under specific UI languages

09 Sep 2019, 04:44

This looks like a great find, but I'm still a bit confused about using SetThreadUILanguage. I thought that whatever language the MsgBox text was written in, for the AutoHotkey program, is what would be displayed. If say you are on a computer where the language is set to Korean, but are using an AutoHotkey application with dialogs and messages written in English, I thought the English AutoHotkey application would properly display English.

Are you trying to set the language for any programs that you install without restarting the computer, using AutoHotkey? Meaning not just for an English AutoHotkey application in a language different from the default on the computer, but for any application that you choose where the language is different.

It's clear what Locale Emulator is doing, but I'm a bit fuzzy on the situations for needing SetThreadUILanguage? Maybe you want to clarify.
Last edited by SOTE on 09 Sep 2019, 05:13, edited 2 times in total.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Run your script under specific UI languages

09 Sep 2019, 05:02

What I meant is, you can use SetThreadUILanguage function, if you don't want to install the software Locale Emulator. :)
before.png
before.png (10.05 KiB) Viewed 5993 times
after.png
after.png (11.74 KiB) Viewed 5993 times
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Run your script under specific UI languages

09 Sep 2019, 05:27

Oh, I understand more clearly now. Thanks for the example.

In Windows 7, 8, and 10, you can have multiple languages set on the computer at the same time. You would go into the Control Panel and select the Language icon, but you might need to download the language pack from Microsoft and it could possibly depend on what version of Windows that you are using. For Windows 8 Pro and Windows 10, Windows isn't "locked" for only a particular language. You can install the language pack, where it will recognize multiple languages.

In a multi-language configured Windows computer, this would likely not be a problem, as you can set the default language to English without restarting. You would change your language preferences, by moving the default up or down. "Control Panel", "Language", "Change Your Language Preferences".

If you are sending software out to people, you can't be sure beforehand how their computer is configured. So I can see where you would want SetThreadUILanguage. But for those type of Runtime errors, you can use #ErrorStdOut (https://www.autohotkey.com/docs/commands/_ErrorStdOut.htm). This would suppress them, so that the user doesn't see them. That's another option, depending on what you want to do. Though maybe you want users to see them or it's for yourself.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Run your script under specific UI languages

09 Sep 2019, 06:20

Thanks for the infomation.
as you can set the default language to English without restarting.
I just tested, that requies at least log off.

I don't want to suppress the error messages, instead, my first intention was:
If your system language is not English, but wanted to provide the English error messages in your post, what would you do?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Run your script under specific UI languages

09 Sep 2019, 08:19

Interesting. Thanks for sharing. There's a list of languages here:
E.g. US = 1033 = 0x0409.
Language Codes | AutoHotkey
https://www.autohotkey.com/docs/misc/Languages.htm
But do you have a way to list the languages available to SetThreadUILanguage?

Btw apparently LANGID is of word type, i.e. a UShort. Cheers.
Windows Data Types - Windows applications | Microsoft Docs
https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types
DllCall("kernel32\SetThreadUILanguage", "UShort",0x0409, "UShort") ;1033
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Run your script under specific UI languages

09 Sep 2019, 09:19

Thanks jeeswg. I've changed the type to "UShort".

The available language IDs can be found at Language Identifier Constants and Strings, but you have to install the language first and then reboot.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Run your script under specific UI languages

09 Sep 2019, 09:46

Thanks, great link.
What I meant was, how to find out which languages are already installed.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Run your script under specific UI languages

09 Sep 2019, 11:03

Works, thanks for sharing :thumbup:.

Cheers.
Spoiler
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Run your script under specific UI languages

09 Sep 2019, 11:34

Thanks Helgef. :thumbup: I only got 1 language (en-US) when I tried your (AHK v2) script. :cry:
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Run your script under specific UI languages

10 Sep 2019, 04:55

That means that You have only 1 installed language with installed "display language pack".

Return to “Tips and Tricks (v1)”

Who is online

Users browsing this forum: No registered users and 21 guests