help to make a language selector Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
19Daniel93
Posts: 40
Joined: 25 Mar 2021, 12:56
Location: La Habana, Cuba

help to make a language selector

18 Apr 2021, 12:58

hello I need help to make a language selector, I also want to know if it is possible that a control type could keep its position to the right and if DropDownList can be extended upwards. Thanks.

this is just an example to learn

Code: Select all

lang_table =
( Join`n `
es,en,de,fr,it
Texto en Español,Text in English,Text in Deutsch,Texte en Français,Testo in Italiano
Español,English,Deutsch,Français,Italiano
Prueba de Idioma,Lenguage test,Sprachtest,Test de langue,Test di lingua
)
	lang = en

i = -1
Loop, Parse, lang_table, `n
{
   i++
   Loop, Parse, A_LoopField, CSV
   {
      If i = 0
      {
         If lang = %A_LoopField%
            j = %A_Index%
      }
      Else If A_Index = %j%
      {
         lang%i% = %A_LoopField%
      }
   }
}

Gui, +Resize +MinSize

Gui, Add, Text, x12 y19 w130 h30 , %lang1%
Gui, Add, Text, x12 y59 w70 h20 , %lang2%
Gui, Add, DropDownList, x229 y68 w40 , es||en|de|fr|it
Gui, Show, x127 y87 h90 w270, %lang3%
Return

GuiClose:
ExitApp

IMG 1.jpg
IMG 1.jpg (25.86 KiB) Viewed 898 times
IMG 2.jpg
IMG 2.jpg (12.54 KiB) Viewed 898 times
IMG 3.jpg
IMG 3.jpg (12.12 KiB) Viewed 898 times
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: help to make a language selector

18 Apr 2021, 14:41

I would use objects, like this:

Code: Select all

lang_table =
( Join`n `
es,en,de,fr,it
Texto en Español,Text in English,Text in Deutsch,Texte en Français,Testo in Italiano
Español,English,Deutsch,Français,Italiano
Prueba de Idioma,Language test,Sprachtest,Test de langue,Test di lingua
)
currLang := "en"
lang := {}
langIndex := []

loop, Parse, lang_table, `n
{
	i := A_Index
	loop, Parse, A_LoopField, CSV
	{
		if (i = 1)
		{
			lang[A_LoopField] := {}
			langIndex[A_Index] := A_LoopField
		}
		else if (i = 2)
			lang[langIndex[A_Index]].text := A_LoopField
		else if (i = 3)
			lang[langIndex[A_Index]].name := A_LoopField
		else if (i = 4)
			lang[langIndex[A_Index]].testPhrase := A_LoopField
	}
}

Gui, +Resize +MinSize

Gui, Add, Text, x12 y19 w130 h30 vText, % lang[currLang].text
Gui, Add, Text, x12 y59 w70 h20 vName, % lang[currLang].name
for each, language in langIndex
	langList .= language . "|"
Gui, Add, DropDownList, x229 y68 w40 gSelect vSelection, % RegExReplace(StrReplace(RTrim(langList, "|"), currLang, currLang . "|"), "\|$", "||")
Gui, Show, x127 y87 h90 w270, % lang[currLang].testPhrase
return

Select:
	Gui, Submit, NoHide
	GuiControl,, Text, % lang[Selection].text
	GuiControl,, Name, % lang[Selection].name
	Gui, Show,, % lang[Selection].testPhrase
return	

GuiClose:
ExitApp

GuiSize:
	GuiControl, Move, Selection, % "x" A_GuiWidth - 42 " y" A_GuiHeight - 22
return

The dropdown list control moves as the window is resized.

I don't know if there is a way to have the dropdown list be forced to go upwards other than to position the GUI window near the bottom of the screen.
19Daniel93
Posts: 40
Joined: 25 Mar 2021, 12:56
Location: La Habana, Cuba

Re: help to make a language selector

18 Apr 2021, 15:53

Thank you very much, now I just have to try to understand it to be able to use it in future projects :thumbup:
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: help to make a language selector

18 Apr 2021, 16:26

You’re welcome. Feel free to ask about anything that’s not clear. The documentation will help a lot, but sometimes the how or why things are implemented a certain way aren’t going to be found there.
19Daniel93
Posts: 40
Joined: 25 Mar 2021, 12:56
Location: La Habana, Cuba

Re: help to make a language selector

21 Apr 2021, 17:25

hi, i've been reviewing the script you sent me and tried to adapt it into another script i've been editing a bit, but i don't know how to do some things. for example there are some vars that I can't change because they have text behind
Original.ahk
(17.75 KiB) Downloaded 16 times
Edited.ahk
(20.65 KiB) Downloaded 14 times
line 215:
Gui, Show, , %lang1% (v%vers%)
%lang1% (v%vers%) to % lang[currLang].Lang01 (v%vers%)

line 280:
FileSelectFile, file, S19, %A_ScriptDir%\Macros\%lang15% %d% - %t%.ahk, %lang13%, %lang17% (*.ahk; *.txt)
%lang15% to % lang[currLang].Lang17
%lang13% to % lang[currLang].Lang15
%lang17% to % lang[currLang].Lang19


I also don't understand how to associate the variables to select:. if there are already others, and if I put the same name the script does not open. Line 217

by the way I added a replay button but I don't know how to make it work either

I'm sorry if I don't express myself correctly, it's that I speak Spanish and I'm writing for the translator
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: help to make a language selector

21 Apr 2021, 18:00

19Daniel93 wrote: line 215:
Gui, Show, , %lang1% (v%vers%)
%lang1% (v%vers%) to % lang[currLang].Lang01 (v%vers%)
It would be:

Code: Select all

Gui, Show,, % lang[currLang].Lang01 " (" v%vers% ")"

19Daniel93 wrote: line 280:
FileSelectFile, file, S19, %A_ScriptDir%\Macros\%lang15% %d% - %t%.ahk, %lang13%, %lang17% (*.ahk; *.txt)
%lang15% to % lang[currLang].Lang17
%lang13% to % lang[currLang].Lang15
%lang17% to % lang[currLang].Lang19
You have to force an expression and use expression syntax if you're using anything other than simple variables that can be surrounded by %. This would be:

Code: Select all

FileSelectFile, file, S19, % A_ScriptDir "\Macros\" lang[currLang].Lang17 " " d " " t ".ahk", % lang[currLang].Lang15, % lang[currLang].Lang19 " (*.ahk; *.txt)"

19Daniel93 wrote: I also don't understand how to associate the variables to select:. if there are already others, and if I put the same name the script does not open. Line 217
If you mean from the GUI controls, you need to get the value of the variable associated with the control of interest. So after you do a Gui, Submit, NoHide, the value of that's in the edit control that has vgui_moveinte in it would be stored in the variable named gui_moveinte.


19Daniel93 wrote: by the way I added a replay button but I don't know how to make it work either
Can you describe what this is supposed to do?
19Daniel93
Posts: 40
Joined: 25 Mar 2021, 12:56
Location: La Habana, Cuba

Re: help to make a language selector

21 Apr 2021, 19:59

Gui, Add, Hotkey, vgui_start xp+50 yp-2 Limit1 gHotkey, %gui_start% ; Start Hotkey
Gui, Add, Button, vlbl3 xm+295 ys-30 w55 Default gStart, % lang[currLang].Lang25 ; Start Button


Gui, Add, Hotkey, vgui_play xp+43 yp-2 Limit1 gHotkey, %gui_play% ; Replay Hotkey
Gui, Add, Button, vlbl5 xm+295 ys w55 Default , % lang[currLang].Lang27 ; Replay Button not work
Img.jpg
Img.jpg (26.51 KiB) Viewed 790 times
I have tried to make it work by looking at the other buttons but there is something that I do not understand and I do not know what it is. I have read the documentation but when I translate it into Spanish it gets a bit tangled.
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: help to make a language selector  Topic is solved

21 Apr 2021, 23:38

Let's take one thing at a time. Otherwise, it gets too confusing trying to communicate back and forth. The dropdown list is blank because you don't have the part where it creates the list before it adds the DropDownList control. You have the third line shown below, but you didn't put the two lines of code before it in your new script:

Code: Select all

for each, language in langIndex
	langList .= language . "|"
Gui, Add, DropDownList, x229 y68 w40 gSelect vSelection, % RegExReplace(StrReplace(RTrim(langList, "|"), currLang, currLang . "|"), "\|$", "||")
Add those two lines, then the dropdown list will work. Let me know when you have that working.
19Daniel93
Posts: 40
Joined: 25 Mar 2021, 12:56
Location: La Habana, Cuba

Re: help to make a language selector

22 Apr 2021, 09:39

:o You're right, I don't know how I didn't realize that I was missing. :thumbup:
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: help to make a language selector

22 Apr 2021, 10:28

For the Replay button to launch the same subroutine that the Replay hotkey does, it appears that you just need to link the subroutine to the control. So this line:

Code: Select all

Gui, Add, Button, vlbl5 xm+295 ys w55 Default , % lang[currLang].Lang27
would become:

Code: Select all

Gui, Add, Button, vlbl5 gPlayTemp xm+295 ys w55 Default , % lang[currLang].Lang27
19Daniel93
Posts: 40
Joined: 25 Mar 2021, 12:56
Location: La Habana, Cuba

Re: help to make a language selector

22 Apr 2021, 11:59

I understand, the subroutine that is launched is PlayTemp:
boiler wrote: If you mean from the GUI controls, you need to get the value of the variable associated with the control of interest. So after you do a Gui, Submit, NoHide, the value of that's in the edit control that has vgui_moveinte in it would be stored in the variable named gui_moveinte.
I also understood this, you have to put it without the v

I think I only have a little problem
Gui, Show,, % lang[currLang].Lang01 " (" v%vers% ")"
it gives me an error
Img.jpg
Img.jpg (46.75 KiB) Viewed 707 times
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: help to make a language selector

22 Apr 2021, 12:26

I see why. When you said you wanted:
%lang1% (v%vers%) to % lang[currLang].Lang01 (v%vers%)

What you really wanted was % lang[currLang].Lang01 "(v" vers ")", so it becomes:

Code: Select all

Gui, Show,, % lang[currLang].Lang01 " (v" vers ")"
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: help to make a language selector

22 Apr 2021, 12:28

Also change this:

Code: Select all

Select:
	Gui, Submit, NoHide
	
	Gui, Show,, % lang[Selection].Lang01
return
to:

Code: Select all

Select:
	Gui, Submit, NoHide
	
	Gui, Show,, % lang[Selection].Lang01 " (v" vers ")"
return
19Daniel93
Posts: 40
Joined: 25 Mar 2021, 12:56
Location: La Habana, Cuba

Re: help to make a language selector

22 Apr 2021, 12:42

Thank you very much, I think that now if it works well, I also learned a lot
19Daniel93
Posts: 40
Joined: 25 Mar 2021, 12:56
Location: La Habana, Cuba

Re: help to make a language selector

22 Apr 2021, 15:28

I'm sorry I thought the translation was complete, but I was missing some details

In the GUI control select: to change the language I already put almost everything, it is that in some they are inside other GUI controls like these

Save:
FileSelectFile, file, S19, % A_ScriptDir "\Macros\" lang[currLang].Lang17 " " d " " t ".ahk", % lang[currLang].Lang15, % lang[currLang].Lang19 " (*.ahk; *.txt)"

Start:
ToolTip, % lang[currLang].Lang24, 5, 5

Stop
ToolTip, % lang[currLang].Lang21, 5, 5

GuiClose:
MsgBox, 20, % lang[currLang].Lang22, % lang[currLang].Lang23

as I could add the variable eg: vgui_moveinte. and in the case of those that have 2 or more% as it would be written in select:

I'm sorry for keeping asking, I really don't want to bother you.
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: help to make a language selector

22 Apr 2021, 16:01

I believe you're saying that you want the currently selected language to appear in those. In that case, you need to replace currLang with Selection. For example:

Code: Select all

FileSelectFile, file, S19, % A_ScriptDir "\Macros\" lang[currLang].Lang17 " " d " " t ".ahk", % lang[currLang].Lang15, % lang[currLang].Lang19 " (*.ahk; *.txt)"
should be:

Code: Select all

FileSelectFile, file, S19, % A_ScriptDir "\Macros\" lang[Selection].Lang17 " " d " " t ".ahk", % lang[Selection].Lang15, % lang[Selection].Lang19 " (*.ahk; *.txt)"

Then it will use the language that has been selected from the dropdown list.
19Daniel93
Posts: 40
Joined: 25 Mar 2021, 12:56
Location: La Habana, Cuba

Re: help to make a language selector

24 Apr 2021, 06:30

Thank you

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, TAC109 and 126 guests