What is the purpose of this and how flexible should this be?
Im guessing only 2 languages will be supported or are you perhaps thinking to add more? I dont think buttons is good for selecting languages. Why not use DDL (drop-down list) instead? Because lots of languages and GUI gets cluttered badly with buttons.
In any case, heres my quick version.
Just copy-paste and it should work.
Variables, ini section and ini keys are not perhaps named properly, you can do that yourself. I arbitrary named them. xD
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Simulates ini file.
/*
[LangList]
ListLng=DUTCH||ENGLISH|GERMAN|SERBIAN|
SelectedLng=DUTCH
[DUTCH]
TEXT1 = Hallo
TEXT2 = Wereld
[ENGLISH]
TEXT1 = Hello
TEXT2 = World
[GERMAN]
TEXT1 = Halo
TEXT2 = Welt
[SERBIAN]
TEXT1 = Halo
TEXT2 = Svet
*/
; Initial reading.
IniRead, ListLng , %A_ScriptDir%\%A_ScriptName%, LangList, ListLng, ERROR
IniRead, SelectedLng , %A_ScriptDir%\%A_ScriptName%, LangList, SelectedLng, ERROR
IniRead, TEXT1, %A_ScriptDir%\%A_ScriptName%, %SelectedLng%, TEXT1
IniRead, TEXT2, %A_ScriptDir%\%A_ScriptName%, %SelectedLng%, TEXT2
; GUI
Gui, Add, DDL, w100 vSelectLang gSelectLang, %ListLng% ; Drop down list
Gui, Add, Text, w100 vText Center, %TEXT1% ; Text
Gui, Add, Button, w100 vButton, %TEXT2% ; Button
Gui, Show
return
; DDL SUB
SelectLang:
Gui, Submit, NoHide
IniRead, TEXT1, %A_ScriptDir%\%A_ScriptName%, %SelectLang%, TEXT1
IniRead, TEXT2, %A_ScriptDir%\%A_ScriptName%, %SelectLang%, TEXT2
GuiControl,, Text, %TEXT1%
GuiControl,, Button, %TEXT2%
StringReplace, ListLng, ListLng, %SelectedLng%||, %SelectedLng%|
StringReplace, ListLng, ListLng, %SelectLang%, %SelectLang%|
SelectedLng := SelectLang
IniWrite, %ListLng%, %A_ScriptDir%\%A_ScriptName%, LangList, ListLng
IniWrite, %SelectedLng%, %A_ScriptDir%\%A_ScriptName%, LangList, SelectedLng
return
; GUI events
GuiEscape:
GuiClose:
exitapp
All you have too do here is list as much languages as you want and in any order.
Make sure to select a default starting one tho.