meoit

Multi Languages and events change the language

31 posts in this topic

#1 ·  Posted (edited)

Hi all!.

Sorry for my bad English.

I am trying to create a Form with support multi languages. But I can not reload the Form as the language selected in the ComboBox.

This is my code:

#include <Constants.au3>
#include <GUIConstants.au3> 
Opt('MustDeclareVars', 1)
;
Global $FormTitle_lng, $LB_SELECT_lng, $CBBOX_LANGS_lng, $LB1_lng, $LB2_lng, $BT1_lng, $BT2_lng
;
Set_Language_for_GUI('default')
;
Global $MAIN_FORM = GUICreate($FormTitle_lng, 315, 170, -1, -1)
Global $LB_SELECT = GUICtrlCreateLabel($LB_SELECT_lng, 10, 10, 93, -1)
Global $CBBOX_LANGS = GUICtrlCreateCombo($CBBOX_LANGS_lng, 105, 10, 195, -1, 0x0003)
GUICtrlSetData(-1, 'English|Thailand|Indonesia')
Global $LB1 = GUICtrlCreateLabel($LB1_lng, 10, 40, 292, -1)
Global $LB2 = GUICtrlCreateLabel($LB2_lng, 10, 72, 292, -1)
Global $BT1 = GUICtrlCreateButton($BT1_lng, 10, 96, 283, -1)
Global $BT2 = GUICtrlCreateButton($BT2_lng, 10, 128, 283, -1)
Global $Selected
GUISetState(@SW_SHOW)
;
While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $CBBOX_LANGS
            $Selected = GUICtrlRead($CBBOX_LANGS)
            Set_Language_for_GUI($Selected)
            ;How to reload GUI on the event change languages of ComboBox
    EndSwitch
WEnd
;
Func Set_Language_for_GUI($MyLang)
    If $MyLang == 'default' Or $MyLang == 'English' Then
        $FormTitle_lng = 'Event on change languages'
        $LB_SELECT_lng = 'Select a language:'
        $CBBOX_LANGS_lng = 'Please select your language'
        $LB1_lng = 'This is Label1 for Langs to show'
        $LB2_lng = 'This is Label2 for Langs to show'
        $BT1_lng = 'Button1 for test lang'
        $BT2_lng = 'Button2 for test lang'
    ElseIf $MyLang == 'Thailand' Then
        $FormTitle_lng = 'เหตุการณ์บนภาษาเปลี่ยนแปลง'
        $LB_SELECT_lng = 'เลือกภาษา:'
        $CBBOX_LANGS_lng = 'กรุณาเลือกภาษาของคุณ'
        $LB1_lng = 'นี่คือ Label1 สำหรับภาษา'
        $LB2_lng = 'นี่คือ Label2 สำหรับภาษา'
        $BT1_lng = 'Button1 สำหรับการทดสอบภาษา'
        $BT2_lng = 'Button2 สำหรับการทดสอบภาษา'
    ElseIf $MyLang == 'Indonesia' Then
        $FormTitle_lng = 'Acara pada bahasa perubahan'
        $LB_SELECT_lng = 'Pilih bahasa:'
        $CBBOX_LANGS_lng = 'Silahkan pilih bahasa Anda'
        $LB1_lng = 'Ini adalah Label1 untuk menampilkan bahasa.'
        $LB2_lng = 'Ini adalah Label2 untuk menampilkan bahasa.'
        $BT1_lng = 'Button1 untuk menampilkan bahasa'
        $BT2_lng = 'Button2 untuk menampilkan bahasa'
    EndIf
Endfunc

multilang9bokh.png

How do I solve this problem ?.

Thanks for support !.

Edited by meoit

Share this post


Link to post
Share on other sites



Hi,

you use the wrong variable name...

because the variable name of the selectet language "inside" the function is $MyLang 

you should use 

 ElseIf $MyLang == 'Thailand'

instead of 

 ElseIf  $Selected == 'Thailand'

Share this post


Link to post
Share on other sites

I changed it as you. But nothing happen.

Share this post


Link to post
Share on other sites

Use GUICtrlSetData to update the text of the controls and WinSetTitle to update the title of your GUI

Share this post


Link to post
Share on other sites

Thanks to @InunoTaishou !

If manual set data are probably take a long time when the GUI have more strings.

Is there a way to set data series for items.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

OK. Done. I manual set data.

This is code:

#include <Constants.au3>
#include <GUIConstants.au3>
Opt('MustDeclareVars', 1)
;
Global $FormTitle_lng, $LB_SELECT_lng, $CBBOX_LANGS_lng, $LB1_lng, $LB2_lng, $BT1_lng, $BT2_lng
Global $SelectedLang
Global $MAIN_FORM, $CTRL_LB_SELECT, $CTRL_CBBOX_LANGS, $CTRL_LB1, $CTRL_LB2, $CTRL_BT1, $CTRL_BT2
;
Get_n_Set_Strings('default')
;
$MAIN_FORM = GUICreate($FormTitle_lng, 315, 170, -1, -1)
$CTRL_LB_SELECT = GUICtrlCreateLabel($LB_SELECT_lng, 10, 10, 93, -1)
$CTRL_CBBOX_LANGS = GUICtrlCreateCombo($CBBOX_LANGS_lng, 105, 10, 195, -1, 0x0003)
GUICtrlSetData(-1, 'English|Thailand|Indonesia')
$CTRL_LB1 = GUICtrlCreateLabel($LB1_lng, 10, 40, 292, -1)
$CTRL_LB2 = GUICtrlCreateLabel($LB2_lng, 10, 72, 292, -1)
$CTRL_BT1 = GUICtrlCreateButton($BT1_lng, 10, 96, 283, -1)
$CTRL_BT2 = GUICtrlCreateButton($BT2_lng, 10, 128, 283, -1)
GUISetState(@SW_SHOW)
;
While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $CTRL_CBBOX_LANGS
            $SelectedLang = GUICtrlRead($CTRL_CBBOX_LANGS)
            Get_n_Set_Strings($SelectedLang)
    EndSwitch
WEnd
;
Func Get_n_Set_Strings($MyLang)
    If $MyLang == 'default' Or $MyLang == 'English' Then
        $FormTitle_lng = 'Event on change languages'
        $LB_SELECT_lng = 'Select a language:'
        $CBBOX_LANGS_lng = 'Please select your language'
        $LB1_lng = 'This is Label1 for Langs to show'
        $LB2_lng = 'This is Label2 for Langs to show'
        $BT1_lng = 'Button1 for test lang'
        $BT2_lng = 'Button2 for test lang'
    ElseIf $MyLang == 'Thailand' Then
        $FormTitle_lng = 'เหตุการณ์บนภาษาเปลี่ยนแปลง'
        $LB_SELECT_lng = 'เลือกภาษา:'
        $CBBOX_LANGS_lng = 'กรุณาเลือกภาษาของคุณ'
        $LB1_lng = 'นี่คือ Label1 สำหรับภาษา'
        $LB2_lng = 'นี่คือ Label2 สำหรับภาษา'
        $BT1_lng = 'Button1 สำหรับการทดสอบภาษา'
        $BT2_lng = 'Button2 สำหรับการทดสอบภาษา'
    ElseIf $MyLang == 'Indonesia' Then
        $FormTitle_lng = 'Acara pada bahasa perubahan'
        $LB_SELECT_lng = 'Pilih bahasa:'
        $CBBOX_LANGS_lng = 'Silahkan pilih bahasa Anda'
        $LB1_lng = 'Ini adalah Label1 untuk menampilkan bahasa.'
        $LB2_lng = 'Ini adalah Label2 untuk menampilkan bahasa.'
        $BT1_lng = 'Button1 untuk menampilkan bahasa'
        $BT2_lng = 'Button2 untuk menampilkan bahasa'
    EndIf
    WinSetTitle($MAIN_FORM, '', $FormTitle_lng)
    SetLang($CTRL_LB_SELECT, $LB_SELECT_lng)
    SetLang($CTRL_CBBOX_LANGS, $CBBOX_LANGS_lng)
    SetLang($CTRL_LB1, $LB1_lng)
    SetLang($CTRL_LB2, $LB2_lng)
    SetLang($CTRL_BT1, $BT1_lng)
    SetLang($CTRL_BT2, $BT2_lng)
Endfunc
Func SetLang($Ctrl, $S)
    GUICtrlSetData($Ctrl, $S)
EndFunc

I still want to set data serials. It is quick and support more Controls.

Is there way to do this ?.

Edited by meoit

Share this post


Link to post
Share on other sites

You could store the IDs of the controls plus the text for all languages in an 2D array.
When you switch the language loop through the array and assign the language dependant text. Quick and dirty:

#include <Constants.au3>
#include <GUIConstants.au3>

Opt('MustDeclareVars', 1)

Global $iGUI_Elements = 4, $iCurrentLanguage = 0, $aGUI[$iGUI_Elements], $aGUILanguage[$iGUI_Elements][2] = [["Window title", "Fenstertitel"], ["LabelCombo", "Text Combo"], ["Label", "Text"], ["Button", "Schaltknopf"]]
Global $idCombo, $idSwitch

$aGUI[0] = GUICreate($aGUILanguage[0][$iCurrentLanguage], 315, 170, -1, -1)
$aGUI[1] = GUICtrlCreateLabel($aGUILanguage[1][$iCurrentLanguage], 10, 10, 93, -1)
$idCombo = GUICtrlCreateCombo("", 105, 10, 195, -1, 0x0003)
GUICtrlSetData(-1, 'English|Thailand|Indonesia')
$aGUI[2] = GUICtrlCreateLabel($aGUILanguage[2][$iCurrentLanguage], 10, 40, 292, -1)
$aGUI[3] = GUICtrlCreateButton($aGUILanguage[3][$iCurrentLanguage], 10, 96, 283, -1)
$idSwitch = GUICtrlCreateButton("Switch language", 10, 130, 100, 20)
GUISetState(@SW_SHOW)
;
While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idSwitch
            _SwitchLanguage()
    EndSwitch
WEnd

Func _SwitchLanguage()
    If $iCurrentLanguage = 0 Then
        $iCurrentLanguage = 1
    Else
        $iCurrentLanguage = 0
    EndIf
    WinSetTitle($aGUI[0], "", $aGUILanguage[0][$iCurrentLanguage])
    For $i = 1 To UBound($aGUI) - 1
        GUICtrlSetData($aGUI[$i], $aGUILanguage[$i][$iCurrentLanguage])
    Next
EndFunc   ;==>_SwitchLanguage

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2016-07-20 - Version 1.2.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks to @water !

Does your code support multiform?.

My GUI have than 2 form.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Sure. I created a second set of language arrays. Set $iCurrentGUI to 1 or 2 to define witch GUI to switch the language.
When creating the second GUI you need to use $aGUI2 and $aGUILanguage2.
NB: The example does not include creation or switching to the second GUI.

#include <Constants.au3>
#include <GUIConstants.au3>

Opt('MustDeclareVars', 1)

Global $iGUI_Elements = 4, $iCurrentLanguage = 0, $iCurrentGUI = 1
Global $aGUI1[$iGUI_Elements], $aGUILanguage1[$iGUI_Elements][2] = [["Window title", "Fenstertitel"], ["LabelCombo", "Text Combo"], ["Label", "Text"], ["Button", "Schaltknopf"]]
Global $aGUI2[$iGUI_Elements], $aGUILanguage2[$iGUI_Elements][2] = [["Window title2", "Fenstertitel2"], ["LabelCombo2", "Text Combo2"], ["Label2", "Text2"], ["Button2", "Schaltknopf2"]]
Global $idCombo, $idSwitch

$aGUI1[0] = GUICreate($aGUILanguage1[0][$iCurrentLanguage], 315, 170, -1, -1)
$aGUI1[1] = GUICtrlCreateLabel($aGUILanguage1[1][$iCurrentLanguage], 10, 10, 93, -1)
$idCombo = GUICtrlCreateCombo("", 105, 10, 195, -1, 0x0003)
GUICtrlSetData(-1, 'English|Thailand|Indonesia')
$aGUI1[2] = GUICtrlCreateLabel($aGUILanguage1[2][$iCurrentLanguage], 10, 40, 292, -1)
$aGUI1[3] = GUICtrlCreateButton($aGUILanguage1[3][$iCurrentLanguage], 10, 96, 283, -1)
$idSwitch = GUICtrlCreateButton("Switch language", 10, 130, 100, 20)
GUISetState(@SW_SHOW)
;
While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idSwitch
            If $iCurrentGUI = 1 Then
                _SwitchLanguage($aGUI1, $aGUILanguage1)
            Else
                _SwitchLanguage($aGUI2, $aGUILanguage2)
            EndIf
    EndSwitch
WEnd

Func _SwitchLanguage($aGUI, $aGUILanguage)
    If $iCurrentLanguage = 0 Then
        $iCurrentLanguage = 1
    Else
        $iCurrentLanguage = 0
    EndIf
    WinSetTitle($aGUI[0], "", $aGUILanguage[0][$iCurrentLanguage])
    For $i = 1 To UBound($aGUI) - 1
        GUICtrlSetData($aGUI[$i], $aGUILanguage[$i][$iCurrentLanguage])
    Next
EndFunc   ;==>_SwitchLanguage

 

Edited by water
1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2016-07-20 - Version 1.2.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Thanks to @water

Which right?.

If $iCurrentGUI = 1 Then
_SwitchLanguage($aGUI1, $aGUILanguage1)
Else
_SwitchLanguage($aGUI1, $aGUILanguage1)
EndIf

Or

If $iCurrentGUI = 1 Then
_SwitchLanguage($aGUI1, $aGUILanguage1)
Else
_SwitchLanguage($aGUI2, $aGUILanguage2)
EndIf

I am trying to put language (after it changed) in the value of the ComboBox. I will feedback again.

Edited by meoit

Share this post


Link to post
Share on other sites

#11 ·  Posted

Ops. Copy & Paste error. I fixed my above post.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2016-07-20 - Version 1.2.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Thanks to @water !

I have changed your code to set the language data to ComboBox. This data is a guide (the first index in ComboBox). But when I click "Switch language", the ComboBox does not change anything until I hit button to 3rd and after ComboBox being loaded, it overlap data.

This is images:

- After load form:

l1taun7.png

- After I hit button "Switch language" to 3rd:

l24budw.png

How to fix this ?.

This is the changed code:

; MultiLanguages in MultiForms and events of them
; Thread by meoit - https://www.autoitscript.com/forum/topic/185604-multi-languages-and-events-change-the-language/
; Code by Water
; Thanks to Water
#include <Constants.au3>
#include <GUIConstants.au3>
;
Opt('MustDeclareVars', 1)
;
Global $iGUI_Elements = 5, $iCurrentLanguage = 0, $iCurrentGUI = 1
Global $aGUI1[$iGUI_Elements], $aGUILanguage1[$iGUI_Elements][2] = [["Window title", "Fenstertitel"], ["LabelCombo", "Text Combo"], ["Notice Combo (default lang)", "Notice Combo (switch lang)"], ["Label", "Text"], ["Button", "Schaltknopf"]]
Global $aGUI2[$iGUI_Elements], $aGUILanguage2[$iGUI_Elements][2] = [["Window title2", "Fenstertitel2"], ["LabelCombo2", "Text Combo2"], ["Label2", "Text2"], ["Button2", "Schaltknopf2"]]
Global $idCombo, $idSwitch
;
$aGUI1[0] = GUICreate($aGUILanguage1[0][$iCurrentLanguage], 315, 170, -1, -1)
$aGUI1[1] = GUICtrlCreateLabel($aGUILanguage1[1][$iCurrentLanguage], 10, 10, 93, -1)
$aGUI1[2] = GUICtrlCreateCombo($aGUILanguage1[2][$iCurrentLanguage], 105, 10, 195, -1, 0x0003)
GUICtrlSetData(-1, 'English|Thailand|Indonesia')
$aGUI1[3] = GUICtrlCreateLabel($aGUILanguage1[3][$iCurrentLanguage], 10, 40, 292, -1)
$aGUI1[4] = GUICtrlCreateButton($aGUILanguage1[4][$iCurrentLanguage], 10, 96, 283, -1)
$idSwitch = GUICtrlCreateButton("Switch language", 10, 130, 100, 20)
GUISetState(@SW_SHOW)
;
While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idSwitch
            If $iCurrentGUI = 1 Then
                _SwitchLanguage($aGUI1, $aGUILanguage1)
            Else
                _SwitchLanguage($aGUI2, $aGUILanguage2)
            EndIf
    EndSwitch
WEnd
;
Func _SwitchLanguage($aGUI, $aGUILanguage)
    If $iCurrentLanguage = 0 Then
        $iCurrentLanguage = 1
    Else
        $iCurrentLanguage = 0
    EndIf
    WinSetTitle($aGUI[0], '', $aGUILanguage[0][$iCurrentLanguage])
    For $i = 1 To UBound($aGUI) - 1
        GUICtrlSetData($aGUI[$i], $aGUILanguage[$i][$iCurrentLanguage])
    Next
EndFunc

Thanks.

Edited by meoit

Share this post


Link to post
Share on other sites

#13 ·  Posted

Something like this? The GUI is changed as soon as you select a different language from the combo:

#include <Constants.au3>
#include <GUIConstants.au3>
#include <StringConstants.au3>

Opt('MustDeclareVars', 1)

Global $iGUI_Elements = 4, $iCurrentLanguage = 0, $iCurrentGUI = 1
Global $iLanguages = 3, $sLanguages = "English|Thailand|Indonesia", $sSelectedLanguage
Global $aGUI1[$iGUI_Elements], $aGUILanguage1[$iGUI_Elements][$iLanguages] = [["English title 1", "Thai title 1", "Indonisian title 1"], ["English Combo 1", "Thai Combo 1", "Indonisian Combo 1"], ["English label 1", "Thai Label 1", "Indonisian Label 1"], ["English Button 1", "Thai Button 1", "Indonisian Button 1"]]
Global $aGUI2[$iGUI_Elements], $aGUILanguage2[$iGUI_Elements][$iLanguages] = [["English title 2", "Thai title 2", "Indonisian title 2"], ["English Combo 2", "Thai Combo 2", "Indonisian Combo 2"], ["English label 2", "Thai Label 2", "Indonisian Label 2"], ["English Button 2", "Thai Button 2", "Indonisian Button 2"]]
Global $idCombo, $aLanguages = StringSplit($sLanguages, "|", $STR_NOCOUNT)

$aGUI1[0] = GUICreate($aGUILanguage1[0][$iCurrentLanguage], 315, 170, -1, -1)
$aGUI1[1] = GUICtrlCreateLabel($aGUILanguage1[1][$iCurrentLanguage], 10, 10, 93, -1)
$idCombo = GUICtrlCreateCombo("", 105, 10, 195, -1, 0x0003)
GUICtrlSetData(-1, $sLanguages, $aLanguages[0])
$aGUI1[2] = GUICtrlCreateLabel($aGUILanguage1[2][$iCurrentLanguage], 10, 40, 292, -1)
$aGUI1[3] = GUICtrlCreateButton($aGUILanguage1[3][$iCurrentLanguage], 10, 96, 283, -1)
GUISetState(@SW_SHOW)

While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idCombo
            $sSelectedLanguage = GUICtrlRead($idCombo)
            ConsoleWrite($sSelectedLanguage & @CRLF)
            For $i = 0 To UBound($aLanguages) - 1
                If $sSelectedLanguage = $aLanguages[$i] Then
                    If $i <> $iCurrentLanguage Then
                        $iCurrentLanguage = $i
                        _SwitchLanguage($aGUI1, $aGUILanguage1)
                        ExitLoop
                    EndIf
                EndIf
            Next
    EndSwitch
WEnd

Func _SwitchLanguage(ByRef $aGUI, ByRef $aGUILanguage)
    Local $iRC = WinSetTitle($aGUI[0], "", $aGUILanguage[0][$iCurrentLanguage])
    For $i = 1 To UBound($aGUI) - 1
        GUICtrlSetData($aGUI[$i], $aGUILanguage[$i][$iCurrentLanguage])
    Next
EndFunc   ;==>_SwitchLanguage

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2016-07-20 - Version 1.2.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#14 ·  Posted

Thanks to @water !.

Can you explain for me this line: $aLanguages = StringSplit($sLanguages, '|', $STR_NOCOUNT) ?.

I am trying to understand your code. I will continue feedback... :)

Share this post


Link to post
Share on other sites

#15 ·  Posted

32 minutes ago, water said:

$aLanguages = StringSplit($sLanguages, "|", $STR_NOCOUNT)

Splits the string into an array. This is needed to set the default language in statement:

33 minutes ago, water said:

GUICtrlSetData(-1, $sLanguages, $aLanguages[0])

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2016-07-20 - Version 1.2.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

@water

I modify your code to add a ComboBox and I want to this combobox will change text (data) when the select languages combobox has changed. But after I hit the select languages combobox, my ComboBox is nothing happen (empty data).

This is first run:

l1j9s24.png

After I hit the select languages combobox:

l27qszs.png

How to fix this ?.

This is the modifed code:

; MultiLanguages in MultiForms and events of them
; Thread by meoit - https://www.autoitscript.com/forum/topic/185604-multi-languages-and-events-change-the-language/
; Code by Water
; Thanks to Water
;
#include <Constants.au3>
#include <GUIConstants.au3>

Opt('MustDeclareVars', 1)

Global $iGUI_Elements = 5, $iCurrentLanguage = 0, $iCurrentGUI = 1
Global $iLanguages = 3, $sLanguages = 'English|Thailand|Indonesia', $sSelectedLanguage
Global $sLanguages_Status = 'Eng, you chose English|Thai, you chose Thai|Indo, you chose Indonisian'
Global $aGUI1[$iGUI_Elements], $aGUILanguage1[$iGUI_Elements][$iLanguages] = [['English title 1', 'Thai title 1', 'Indonisian title 1'], ['English Combo 1', 'Thai Combo 1', 'Indonisian Combo 1'], [$sLanguages_Status], ['English label 1', 'Thai Label 1', 'Indonisian Label 1'], ['English Button 1', 'Thai Button 1', 'Indonisian Button 1']]
Global $aGUI2[$iGUI_Elements], $aGUILanguage2[$iGUI_Elements][$iLanguages] = [['English title 2', 'Thai title 2', 'Indonisian title 2'], ['English Combo 2', 'Thai Combo 2', 'Indonisian Combo 2'], ['English label 2', 'Thai Label 2', 'Indonisian Label 2'], ['English Button 2', 'Thai Button 2', 'Indonisian Button 2']]
Global $idCombo, $aLanguages = StringSplit($sLanguages, '|', $STR_NOCOUNT)
Global $idCombo_Status, $aLanguages_Status = StringSplit($sLanguages_Status, '|', $STR_NOCOUNT)
$aGUI1[0] = GUICreate($aGUILanguage1[0][$iCurrentLanguage], 315, 170, -1, -1)
$aGUI1[1] = GUICtrlCreateLabel($aGUILanguage1[1][$iCurrentLanguage], 10, 10, 93, -1)
$idCombo = GUICtrlCreateCombo('', 105, 10, 195, -1, 0x0003)
GUICtrlSetData(-1, $sLanguages, $aLanguages[0])
$aGUI1[2] = GUICtrlCreateCombo('', 105, 40, 195, -1, 0x0003)
GUICtrlSetData(-1, $aGUILanguage1[2][$iCurrentLanguage], $aLanguages_Status[0])
$aGUI1[3] = GUICtrlCreateLabel($aGUILanguage1[3][$iCurrentLanguage], 10, 40, 292, -1)
$aGUI1[4] = GUICtrlCreateButton($aGUILanguage1[4][$iCurrentLanguage], 10, 126, 283, -1)
GUISetState(@SW_SHOW)

While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idCombo
            $sSelectedLanguage = GUICtrlRead($idCombo)
            ;ConsoleWrite($sSelectedLanguage & @CRLF)
            For $i = 0 To UBound($aLanguages) - 1
                If $sSelectedLanguage = $aLanguages[$i] Then
                    If $i <> $iCurrentLanguage Then
                        $iCurrentLanguage = $i
                        _SwitchLanguage($aGUI1, $aGUILanguage1)
                        ExitLoop
                    EndIf
                EndIf
            Next
    EndSwitch
WEnd

Func _SwitchLanguage(ByRef $aGUI, ByRef $aGUILanguage)
    Local $iRC = WinSetTitle($aGUI[0], '', $aGUILanguage[0][$iCurrentLanguage])
    For $i = 1 To UBound($aGUI) - 1
        GUICtrlSetData($aGUI[$i], $aGUILanguage[$i][$iCurrentLanguage])
    Next
EndFunc   ;==>_SwitchLanguage

Thanks.

Edited by meoit

Share this post


Link to post
Share on other sites

#17 ·  Posted

What's the purpose of the second combo?

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2016-07-20 - Version 1.2.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#18 ·  Posted

In the Second Combo, I want to display a text line (example: "Please select method" Or "Please select product...") at first index of the Second Combo. This text line also change language after I choose value "English Or Thailand Or Indonesian" in the Language Combo.

Share this post


Link to post
Share on other sites

#19 ·  Posted

I see. But why not use a simple label?
So you have a combo to select the language from and a label that simply says (in the currently selected language): "Please select a language".

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2016-07-20 - Version 1.2.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#20 ·  Posted

I need to reduce the area of the GUI/Form.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now