AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Create AHK script with different GUI Languages
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
niwi



Joined: 27 Feb 2005
Posts: 128
Location: Heidelberg, Germany

PostPosted: Sun Mar 06, 2005 10:41 am    Post subject: Create AHK script with different GUI Languages Reply with quote

Hi,

I'm back again Wink
I'm writing an application with AHK and I'd like to switch the GUI language (I'm german, but I want to support english too).
I know that it is possible to change the text of buttons, static text etc. I'm just thinking about how to program this. My idea is:
set a variable to the initial language if nothing else is stored
Code:
set var_guilang = DEU
; set var_guilang = ENU


call a subroutine to set a lot of variables for every element
Code:
set var_element1_DEU = Speichern
set var_element1_ENU = Save

set var_element2_DEU = Laden
set var_element2_ENU = Load


I have a radio button to switch between the languages, so if this changes another sub routine will be called which changes the text of the elements
Code:
GuiControl,, var_element1, % var_element1_%var_guilang%


Or is there a better solution for this?

Regards, NiWi.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Sun Mar 06, 2005 11:52 am    Post subject: Reply with quote

You can also use the built-in variable A_Language to make an initial guess about the user's language.

Another thing you can do is use the control's own variable to store its initial text:
Code:
if A_Language in 0407,0807,0c07,1007,1407
{   
   ;0407 German_Standard
   ;0807 German_Swiss
   ;0c07 German_Austrian
   ;1007 German_Luxembourg
   ;1407 German_Liechtenstei
   Language = DEU
}
else
{
   Language = ENU
}

Gosub, FillVariablesUsingLangauge

Gui, Add, Text, vIntro, %Intro%
Gui, Show
return



FillVariablesUsingLangauge:
if Language = DEU
{
   Intro = German intro.
   ; ... and other variables
}
else  ; Language = ENU
{
   Intro = English intro.
   ; ... and other variables
}
Back to top
View user's profile Send private message Send e-mail
BoBo
Guest





PostPosted: Sun Mar 06, 2005 12:07 pm    Post subject: Reply with quote

3 Options:
a) separate language dat's ie 49.dat;01.dat;31.dat;... (no. = country code)
b) single lang.dat which contains language fields
c) single lang.ini which contains language sections

The following code is based on b)

Code:
Gui, Add, Radio, vR1, Deutsch
Gui, Add, Radio,, English
Gui, Add, Button,, &OK
Gui, Show
Return


ButtonOK:
Gui, Submit
If R1 = 1
   FieldNo = 2
If R1 = 2
   FieldNo = 1

Loop, Read, Lang.dat
   {
   StringSplit, Field, A_LoopReadLine,|
   Var := Field%FieldNo%
   MsgBox, Buttonbeschriftung: %var%
   }


Lang.dat
Quote:
Save|Speichern
Cancel|Abbrechen
Close|Schließen
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Sun Mar 06, 2005 1:11 pm    Post subject: Reply with quote

Nice.
Back to top
View user's profile Send private message Send e-mail
niwi



Joined: 27 Feb 2005
Posts: 128
Location: Heidelberg, Germany

PostPosted: Sun Mar 06, 2005 2:41 pm    Post subject: Reply with quote

Hi,

using ini files it will be possible to do something like this:
[Languages]
lang1=DEU
codes1=0407 0807 0c07 1007 1407
lang2=ENU
codes2=0409...

[Text_DEU]
Text01=blabla

[Text_ENU]
Text01=yadayada

Or inlcude them all into the main script.

Ok, thank your for the ideas, I'm trying to figure out wich one is the best to use.

Another question:
Is it possible to change the text of the tabs? I have tabs with german text and I can switch the language to english, so my few controls now will switch to english, but I can't do this with the tabs.

I can access the tabs by using the number associated to them, i.e.
Gui, Tab, 3
Gui, Add, Text...
but I haven't found a way to change the text. Or have I to create the tab twice and using the hide / unhide mechanism?

NiWi.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Sun Mar 06, 2005 9:19 pm    Post subject: Reply with quote

niwi wrote:
Is it possible to change the text of the tabs?
You can change the text with GuiControl as in this example:

GuiControl,, MyTab, |First Name|Second Name|Third Name

.. where "MyTab" is the variable name you assigned at the time of creation:
Gui, Add, Tab, vMyTab, First Name|Second Name|Third Name

Edit: Added leading pipe for "GuiControl" above.


Last edited by Chris on Wed Mar 09, 2005 3:07 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
niwi



Joined: 27 Feb 2005
Posts: 128
Location: Heidelberg, Germany

PostPosted: Tue Mar 08, 2005 7:08 am    Post subject: Reply with quote

Hi Chris,

Chris wrote:
niwi wrote:
Is it possible to change the text of the tabs?
You can change the text with GuiControl as in this example:

GuiControl,, MyTab, First Name|Second Name|Third Name

.. where "MyTab" is the variable name you assigned at the time of creation:
Gui, Add, Tab, vMyTab, First Name|Second Name|Third Name

You forgot (like me) the first pipe in the GuiControl command:
Code:
GuiControl,, MyTab, |First Name|Second Name|Third Name


My next problem is using arrays like this:
Code:

Gui, Add, Tab, vMyTab, X|Y
myArray0[0] = A1
myArray0[1] = A2
myArray1[0] = B1
myArray1[1] = B2
i = 0
GuiControl,, MyTab, % |myArray0[%i%]|myArray1[%i%]

won't work, because of using the single % will change the end of line into an expression, where the pipe is a bitwise OR...
Do you have an easy way to handle this? Maybe you can add the double %% as variables which can be used like this:
Code:

GuiControl,, MyTab, |%%myArray0[%i%]%%|%%myArray1[%i%]%%

This looks not very clear, but this way I can use a variable in a variable.

Regards, NiWi.
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Tue Mar 08, 2005 8:21 am    Post subject: Reply with quote

you could as well do this, right?
Code:
i = 0
Lable1 := myArray0[%i%]
Lable2 := myArray1[%i%]
GuiControl,, MyTab, |%Lable1%|%Lable2%

_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
niwi



Joined: 27 Feb 2005
Posts: 128
Location: Heidelberg, Germany

PostPosted: Tue Mar 08, 2005 10:46 am    Post subject: Reply with quote

Hi,

this is what I do, but with more than two variables it is not very pretty. Ok, I use a loop at the moment, copy the strings and concatenate them, but it is not simple or very handy at all.

NiWi.
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Tue Mar 08, 2005 11:30 am    Post subject: Reply with quote

But it will not be easier if you would have to do the thing you wanted to do:
Quote:
GuiControl,, MyTab, |%%myArray0[%i%]%%|%%myArray1[%i%]%%


This will get even more complicated with more then 2 Labels.

Don't get me wrong, but I prefer KISS (keep it stupid simple/keep it simple, stupid) ((c) BoBo)
Do one thing at a time and do it correct. Then do the next thing. It prevents bugs. The script is easier to maintain and extend. And other users can read and understand the code.

Why not put the TabLabelString as a whole in the ini? Then you do not have to concate?
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
niwi



Joined: 27 Feb 2005
Posts: 128
Location: Heidelberg, Germany

PostPosted: Tue Mar 08, 2005 12:15 pm    Post subject: Reply with quote

Hi,

toralf wrote:
But it will not be easier if you would have to do the thing you wanted to do:
Quote:
GuiControl,, MyTab, |%%myArray0[%i%]%%|%%myArray1[%i%]%%


This will get even more complicated with more then 2 Labels.

Don't get me wrong, but I prefer KISS (keep it stupid simple/keep it simple, stupid) ((c) BoBo)

But copying large strings to temporary variables is not very effective Sad

toralf wrote:
Do one thing at a time and do it correct. Then do the next thing. It prevents bugs. The script is easier to maintain and extend. And other users can read and understand the code.

This is one point for you. Razz

toralf wrote:
Why not put the TabLabelString as a whole in the ini? Then you do not have to concate?

This won't work. I've tried something like this:
Code:

myString = |A1|B1|C1

but I haven't get the complete string. Maybe
Code:

myString := "|A1|B1|C1"

would be better (I haven't tried this, but I will test it).
Back to top
View user's profile Send private message
Guest






PostPosted: Tue Mar 08, 2005 12:51 pm    Post subject: Reply with quote

AFAIK
Code:
myString=|A1|B1|C1

should work.
Back to top
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Tue Mar 08, 2005 4:06 pm    Post subject: Reply with quote

The choice between := "" and = is purely a matter of preference. Personally, I prefer the former. Wink
Back to top
View user's profile Send private message
niwi



Joined: 27 Feb 2005
Posts: 128
Location: Heidelberg, Germany

PostPosted: Tue Mar 08, 2005 4:28 pm    Post subject: Reply with quote

Hi,

ok, here is a little script, it is nearly to that one I'm using, but I tried to keep it simple:
Code:

var1 = A
var2 = B

Gui, Add, Tab, vmyTab, 1|2
Gui,Show

MsgBox, now changing.

i1 = 1
i2 = 2
GuiControl,, myTab, % |var%i1%|var%i2%

newtab := "|" var%i1% "|" var%i2%
MsgBox, second try: %newTab%
GuiControl,, myTab, %newTab%

dummy1 := var%i1%
dummy2 := var%i2%
newtab := "|" dummy1 "|" dummy2
MsgBox, third try: %newTab%
GuiControl,, myTab, %newTab%

MsgBox, Finished.
ExitApp

What it should do:
Create a GUI with two tabs called "1" and "2". I'd like to change the names depending on an index variable and using an array.

So the only way I could do this is to use some dummies and set them to the array values. After this I can concatenate them to one string.

NiWi.
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Tue Mar 08, 2005 4:39 pm    Post subject: Reply with quote

Yes, As it is stated in the manual:
Quote:
Currently, sub-expressions and references such as Array%i% cannot be merged with other items. An attempt to merge a sub-expression such as "Prefix" (x + 1) will cause the entire expression to evaluate to an empty string. An attempt to merge a reference such as Array%i% "Suffix" will treat Array%i% as an empty string.


See Expressions -> Concate
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group