 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
haichen
Joined: 05 Feb 2007 Posts: 110 Location: Osnabrück, Germany
|
Posted: Sun Feb 24, 2008 3:49 pm Post subject: [include] LangHelp.ahk to make multilanguage scripts |
|
|
There are some things you can do easily with this script:
The tray menu isnt shown, though you also can change the language there
1. Write scripts for different languages.
2. Enable dynamic change of the language in your script.
3. Change existent scripts with only one language to one with plenty different languages.
4. Add very easily some more languages (Let it do the users).
5. Your menus are build automatically.
Add a menubar, a traymenu or a bar with radiobuttons for changing the Language.
There are only a few steps to add the language functionality to your script:
1. At first you`ve to add Include LangHelp.ahk as an #include at the end of your script.
2. Add a Var that includes all translations.
it should look like the IniVar in the Examplecode.
if you later want to add some more, change the line possibleLangs and add the translation as a section.
Please attend this point: MenulangugeTitel comprised the name/titel of the Menus.
change
possibleLangs=de,en,fr --> possibleLangs=de,en,fr,es
and add this
[es]
MenulanguageTitel=La Lengua
testvar =espaniol
3. Load the languagevariable (IniVar) with LangHelp_LoadLanguageVars(IniVar,"updateLang") function.
"updateLang" is the later used Label to dynamic update your translations. If you use a MenuBar, you've to add the name of the Bar.
For instance: LangHelp_LoadLanguageVars(IniVar,"updateLang","MyMenu")
4. Add one or all Menu's you want to have with these three functions:
Menualt := LangHelp_showLangTrayMenu(possibleLangs, MenulanguageTitel)
LangHelp_showLangMenu(possibleLangs, MenulanguageTitel)
LangHelp_showLangRadioMenu(possibleLangs, actualLang)
if you use the first or second function you've to add once a return value. It remembers the the former
menuname, because for changing menus you need the menutext (I think so).
5. Last not least you need a Label updateLang: to change and update your controls. It is mentioned in step3.
In the download file you can see a more complex example.
Perhaps it looks difficult, but try it. Its easy.
Beispiel:
| Code: |
IniVar=
(
[lang]
actualLang=fr
possibleLangs=de,en,fr
[de]
MenulanguageTitel=Sprachauswahl
testvar =deutsch
[en]
MenulanguageTitel=Languages
testvar =english
[fr]
MenulanguageTitel=Language
testvar =francais
)
;------------------------------------------
LangHelp_LoadLanguageVars(IniVar,"updateLang")
;------------------------------------------
Gui,Add, text, vtestvar w300, testvar=%testvar%
Gui,Add, text,
;------------------------------------------
Menualt := LangHelp_showLangTrayMenu(possibleLangs, MenulanguageTitel)
LangHelp_showLangMenu(possibleLangs, MenulanguageTitel)
LangHelp_showLangRadioMenu(possibleLangs, actualLang)
;------------------------------------------
Gui,Show, ,Language - Sprache
Return
;------------------------------------------
updateLang:
GuiControl, ,testvar, testvar=%testvar%
return
;------------------------------------------
esc::
GuiEscape:
GuiClose:
ExitApp
Return
;------------------------------------------
#include LangHelp.ahk
;------------------------------------------
|
Download LangHelp.ahk
a little bit more complex example
I've made the Variable with the translations looks like an INI-file and certainly you can use one with readfile. If you do so you can use iniwrite to update the var actualLang in updateLabel:.
I hope this will be useful.
I've tried the automatical documentation with NaturalDocs.
And here's the result

Last edited by haichen on Mon Feb 25, 2008 3:13 pm; edited 1 time in total |
|
| Back to top |
|
 |
Jero3n
Joined: 19 Jan 2007 Posts: 151
|
Posted: Sun Feb 24, 2008 4:22 pm Post subject: |
|
|
Why isn't the following working:
test.ahk
| Code: |
FileRead, language, test.ini
; ---------------------------------------------------------------------
LangHelp_LoadLanguageVars(language,"updateLang")
; ---------------------------------------------------------------------
Gui,Add, text, vtestvar w300, testvar=%testvar%
Gui,Add, text,
; ---------------------------------------------------------------------
Menualt := LangHelp_showLangTrayMenu(possibleLangs, MenulanguageTitel)
LangHelp_showLangMenu(possibleLangs, MenulanguageTitel)
LangHelp_showLangRadioMenu(possibleLangs, actualLang)
; ---------------------------------------------------------------------
Gui,Show, ,Language - Sprache
Return
; ---------------------------------------------------------------------
updateLang:
GuiControl, ,testvar, testvar=%testvar%
return
; ---------------------------------------------------------------------
esc::
GuiEscape:
GuiClose:
ExitApp
Return
#include LangHelp.ahk
|
test.ini
| Code: |
[lang]
actualLang=fr
possibleLangs=de,en,fr
[de]
MenulanguageTitel=Sprachauswahl
testvar =deutsch
[en]
MenulanguageTitel=Languages
testvar =english
[fr]
MenulanguageTitel=Language
testvar =francais
|
P.S The loading works, but the changing of the objects doens't :S _________________
Watch my css video! |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 110 Location: Osnabrück, Germany
|
Posted: Sun Feb 24, 2008 6:46 pm Post subject: |
|
|
Now it should work. Please download LangHelp again.
I have to think more about globals, sorry.
if you put this
| Code: | | IniWrite, %actualLang%, test.ini, lang, actualLang | in the updatelang: label, your script restarts with the last changed languge.
Thanks for your try.
 |
|
| Back to top |
|
 |
Jero3n
Joined: 19 Jan 2007 Posts: 151
|
Posted: Mon Feb 25, 2008 9:05 am Post subject: |
|
|
With the new one it works, thanks!
Good idea to make this
[EDIT] Another think I can't get working
How can I integrate the menu into this menu:
| Code: |
Menu, ImportMenu, Add, %MenuImportFile%, ImportFile
Menu, ImportMenu, Add, %MenuImportFolder%, ImportFolder
Menu, JumpMenu, Add, Official website, Blank
Menu, JumpMenu, Add, Forum, Blank
Menu, JumpMenu, Add, Chat, Blank
Menu, Filemenu, Add, %MenuImportTitle%, :ImportMenu
Menu, Filemenu, Add, Export, Blank
Menu, Filemenu, Add, Settings, Blank
Menu, FileMenu, Add, Exit, Exit
Menu, Edit, Add, Cut, Blank
Menu, Edit, Add, Copy, Blank
Menu, Edit, Add, Past, Blank
Menu, Edit, Add, Undo, Blank
Menu, Edit, Add
Menu, Edit, Add, Select all, Blank
Menu, Music, Add, Play/Pause, PlayPause
Menu, Music, Add, Stop, Stop
Menu, Music, Add, Next, Blank
Menu, Music, Add, Previous, Blank
Menu, Music, Add, Shuffle, ToggleCheckShuffle
Menu, Help, Add, Help, Blank
Menu, Help, Add, Support, Blank
Menu, Help, Add, FAQ, Blank
Menu, Help, Add, Hotkeys, Blank
Menu, Help, Add
Menu, Help, Add, Check updates, Blank
Menu, Help, Add, Jump to, :JumpMenu
Menu, Help, Add, About, Blank
Menu, MyMenu, Add, File, :FileMenu
Menu, MyMenu, Add, Edit, :Edit
Menu, MyMenu, Add, Music, :Music
Menu, MyMenu, Add, Help, :Help
Gui, Menu, MyMenu
Menu, LVMenu, Add, Play, PlayLVItem
Menu, LVMenu, Add, Copy, Blank
Menu, LVMenu, Add, Delete, DeleteTrack
Menu, LVMenu, Add
Menu, LVMenu, Add, Add to favorites, Blank
Menu, LVMenu, Add, Get matching tracks, Blank
Menu, LVMenu, Add
Menu, LVRateMenu, Add, 5, Rate5
Menu, LVRateMenu, Add, 4, Rate4
Menu, LVRateMenu, Add, 3, Rate3
Menu, LVRateMenu, Add, 2, Rate2
Menu, LVRateMenu, Add, 1, Rate1
Menu, LVMenu, Add, Rate, :LVRateMenu
Menu, LVMenu, Add
Menu, LVMenu, Add, Properties, ShowProperties
|
When I place it in the middle or in the beginning, I see no languag menu, and when I place it in the end, I just see the language menu :S _________________
Watch my css video! |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 110 Location: Osnabrück, Germany
|
Posted: Mon Feb 25, 2008 2:36 pm Post subject: |
|
|
Gratulations for being my alpha-Tester Jero3n!
Thanks a lot!!
Sorry, one Error was the name of the menubar. I used somewhere "MyMenuBar" and you "MyMenu". Now I added a third parameter for the MenuBarName in LangHelp_LoadLanguageVars.
Please, redownload LangHelp.ahk.
The following code works (so far..)
| Code: |
FileRead, language, test.ini
;------------------------------------------
LangHelp_LoadLanguageVars(language,"updateLang","MyMenu")
;------------------------------------------
Menu, ImportMenu, Add, %MenuImportFile%, ImportFile
Menu, ImportMenu, Add, %MenuImportFolder%, ImportFolder
Menu, JumpMenu, Add, Official website, Blank
Menu, JumpMenu, Add, Forum, Blank
Menu, JumpMenu, Add, Chat, Blank
Menu, Filemenu, Add, %MenuImportTitle%, :ImportMenu
Menu, Filemenu, Add, Export, Blank
Menu, Filemenu, Add, Settings, Blank
Menu, FileMenu, Add, Exit, Exit
Menu, Edit, Add, Cut, Blank
Menu, Edit, Add, Copy, Blank
Menu, Edit, Add, Past, Blank
Menu, Edit, Add, Undo, Blank
Menu, Edit, Add
Menu, Edit, Add, Select all, Blank
Menu, Music, Add, Play/Pause, PlayPause
Menu, Music, Add, Stop, Stop
Menu, Music, Add, Next, Blank
Menu, Music, Add, Previous, Blank
Menu, Music, Add, Shuffle, ToggleCheckShuffle
Menu, Help, Add, Help, Blank
Menu, Help, Add, Support, Blank
Menu, Help, Add, FAQ, Blank
Menu, Help, Add, Hotkeys, Blank
Menu, Help, Add
Menu, Help, Add, Check updates, Blank
Menu, MyMenu, Add, Jump to, :JumpMenu
Menu, Help, Add, About, Blank
Menu, MyMenu, Add, File, :FileMenu
Menu, MyMenu, Add, Edit, :Edit
Menu, MyMenu, Add, Musik, :Music
Menu, MyMenu, Add, Help, :Help
Menu, LVMenu, Add, Play, PlayLVItem
Menu, LVMenu, Add, Copy, Blank
Menu, LVMenu, Add, Delete, DeleteTrack
Menu, LVMenu, Add
Menu, LVMenu, Add, Add to favorites, Blank
Menu, LVMenu, Add, Get matching tracks, Blank
Menu, LVMenu, Add
Menu, LVRateMenu, Add, 5, Rate5
Menu, LVRateMenu, Add, 4, Rate4
Menu, LVRateMenu, Add, 3, Rate3
Menu, LVRateMenu, Add, 2, Rate2
Menu, LVRateMenu, Add, 1, Rate1
Menu, LVMenu, Add, Rate, :LVRateMenu
Menu, LVMenu, Add
Menu, LVMenu, Add, Properties, ShowProperties
Menu, MyMenu, Add, %LVMenu%, :LVMenu
Gui, Menu, MyMenu
;------------------------------------------
; beim Wechsel der Sprache müssen die alten Menünamen gespeichert werden
; the old Menunames must be saved before changing
oldMenuImportFile := MenuImportFile
oldMenuImportFolder := MenuImportFolder
oldMenuImportTitle := MenuImportTitle
oldLVMenu := LVMenu
Menualt := LangHelp_showLangTrayMenu(possibleLangs, MenulanguageTitel)
LangHelp_showLangMenu(possibleLangs, MenulanguageTitel)
LangHelp_showLangRadioMenu(possibleLangs, actualLang)
;------------------------------------------
Gui,Add, text, vOptionsLang w300, OptionsLang=hallo
Gui,Show,,Language - Sprache
Return
/*
;------------- minimum Version------------------
;Wenn die Sprache erst durch Neuladen verändert werden soll
;reicht das
;You can also do the update with reload
updateLang:
IniWrite, %actualLang%, test.ini, lang, actualLang
reload
return
*/
;/*
updateLang:
;---this is up to yours ----------------------
; update your controls
; Hier müssen die eigenen Controls aktualisiert werden
IniWrite, %actualLang%, test.ini, lang, actualLang
If (oldMenuImportFile<>MenuImportFile)
Menu, ImportMenu, Rename, %oldMenuImportFile%,%MenuImportFile%
oldMenuImportFile:=MenuImportFile
If (oldMenuImportFolder<>MenuImportFolder)
Menu, ImportMenu, Rename, %oldMenuImportFolder%, %MenuImportFolder%
oldMenuImportFolder:=MenuImportFolder
If (oldMenuImportTitle<>MenuImportTitle)
Menu, Filemenu, Rename, %oldMenuImportTitle%, %MenuImportTitle%
oldMenuImportTitle:=MenuImportTitle
If (oldLVMenu<>LVMenu)
Menu,MyMenu,Rename,%oldLVMenu%,%LVMenu%
oldLVMenu=%LVMenu%
Return
;*/
importfolder:
msgbox, hallo %A_ThisMenu%
return
importfile:
msgbox, hallo %A_ThisMenu%
return
playpause:
msgbox, hallo %A_ThisMenu%
return
showproperties:
msgbox, hallo %A_ThisMenu%
return
rate5:
msgbox, hallo %A_ThisMenu%
return
rate4:
msgbox, hallo %A_ThisMenu%
return
rate3:
msgbox, hallo %A_ThisMenu%
return
rate2:
msgbox, hallo %A_ThisMenu%
return
rate1:
msgbox, hallo %A_ThisMenu%
return
deletetrack:
msgbox, hallo %A_ThisMenu%
return
playLVItem:
msgbox, hallo %A_ThisMenu%
return
exit:
msgbox, hallo %A_ThisMenu%
return
togglecheckshuffle:
msgbox, hallo %A_ThisMenu%
return
blank:
msgbox, hallo %A_ThisMenu%
return
stop:
msgbox, hallo %A_ThisMenu%
return
^o::
void:
msgbox, hallo %A_ThisMenu%
return
esc::
GuiEscape:
GuiClose:
ExitApp
Return
#include LangHelp.ahk
|
test.ini :
| Code: | [lang]
actualLang=fr
possibleLangs=de,en,fr,kl
[de]
MenulanguageTitel=Sprachauswahl
MenuImportFile =fileimport deutsch
MenuImportFolder =folderimport deutsch
MenuImportTitle =Import deutsch
LVMenu =LV Menu de
[en]
MenulanguageTitel=Languages
MenuImportFile = fileimport english
MenuImportFolder = folderimport english
MenuImportTitle = Import english
LVMenu =LV Menu en
[fr]
MenulanguageTitel=Language
MenuImportFile =fileimportfrancaise
MenuImportFolder =folderimportfrancaise
MenuImportTitle =Importfrancaise
LVMenu =LV Menu fr
[kl]
MenulanguageTitel=Language
MenuImportFile =fileimportfrancaise
MenuImportFolder =folderimportfrancaise
MenuImportTitle =Importfrancaise
LVMenu =LV Menu kl
|
|
|
| Back to top |
|
 |
Jero3n
Joined: 19 Jan 2007 Posts: 151
|
Posted: Mon Feb 25, 2008 5:25 pm Post subject: |
|
|
It works now
Also, I have got two suggestions.
1. Make it so that you can add the language menu as a submenu (so that you can make a menu like Preferences->Languages
2. Make it possible that you can have Preferences->Languages->English|Dutch|French instead of en,nl,fr _________________
Watch my css video! |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 110 Location: Osnabrück, Germany
|
Posted: Mon Feb 25, 2008 6:21 pm Post subject: |
|
|
The second point is easy, change the inifile (or the iniVar):
| Code: | [lang]
actualLang=Dutch
possibleLangs=Dutch,English,French
[Dutch]
... |
|
|
| Back to top |
|
 |
Jero3n
Joined: 19 Jan 2007 Posts: 151
|
Posted: Mon Feb 25, 2008 6:32 pm Post subject: |
|
|
Oops, you're right
And what about the second one?
P.S update the documentation _________________
Watch my css video! |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 110 Location: Osnabrück, Germany
|
Posted: Mon Feb 25, 2008 7:31 pm Post subject: |
|
|
I thougt I cant do your first point.
But ...here it is.
You've to update your LangHelp.ahk
As an example I take your code.
Three things changed:
| Code: | | oldtitel := MenulanguageTitel |
to remember the MenuTitel
| Code: | | LangHelp_showLangMenu(possibleLangs, MenulanguageTitel,"LVRateMenu") |
"LVRateMenu" says where to include the Languagemenu
if it is "" it will be shown as a mainmenu at the end of the others.
to update also the Languagemenu you put this in the "updateLang:" Label
| Code: | If (oldtitel<>MenulanguageTitel)
Menu,LVRateMenu,Rename,%oldtitel%,%MenulanguageTitel%
oldtitel=%MenulanguageTitel%
|
Here is it alltogether:
| Code: |
FileRead, language, test.ini
;------------------------------------------
LangHelp_LoadLanguageVars(language,"updateLang","MyMenu")
;------------------------------------------
Menu, ImportMenu, Add, %MenuImportFile%, ImportFile
Menu, ImportMenu, Add, %MenuImportFolder%, ImportFolder
Menu, JumpMenu, Add, Official website, Blank
Menu, JumpMenu, Add, Forum, Blank
Menu, JumpMenu, Add, Chat, Blank
Menu, Filemenu, Add, %MenuImportTitle%, :ImportMenu
Menu, Filemenu, Add, Export, Blank
Menu, Filemenu, Add, Settings, Blank
Menu, FileMenu, Add, Exit, Exit
Menu, Edit, Add, Cut, Blank
Menu, Edit, Add, Copy, Blank
Menu, Edit, Add, Past, Blank
Menu, Edit, Add, Undo, Blank
Menu, Edit, Add
Menu, Edit, Add, Select all, Blank
Menu, Music, Add, Play/Pause, PlayPause
Menu, Music, Add, Stop, Stop
Menu, Music, Add, Next, Blank
Menu, Music, Add, Previous, Blank
Menu, Music, Add, Shuffle, ToggleCheckShuffle
Menu, Help, Add, Help, Blank
Menu, Help, Add, Support, Blank
Menu, Help, Add, FAQ, Blank
Menu, Help, Add, Hotkeys, Blank
Menu, Help, Add
Menu, Help, Add, Check updates, Blank
Menu, MyMenu, Add, Jump to, :JumpMenu
Menu, Help, Add, About, Blank
Menu, MyMenu, Add, File, :FileMenu
Menu, MyMenu, Add, Edit, :Edit
Menu, MyMenu, Add, Musik, :Music
Menu, MyMenu, Add, Help, :Help
Menu, LVMenu, Add, Play, PlayLVItem
Menu, LVMenu, Add, Copy, Blank
Menu, LVMenu, Add, Delete, DeleteTrack
Menu, LVMenu, Add
Menu, LVMenu, Add, Add to favorites, Blank
Menu, LVMenu, Add, Get matching tracks, Blank
Menu, LVMenu, Add
Menu, LVRateMenu, Add, 5, Rate5
Menu, LVRateMenu, Add, 4, Rate4
Menu, LVRateMenu, Add, 3, Rate3
Menu, LVRateMenu, Add, 2, Rate2
Menu, LVRateMenu, Add, 1, Rate1
Menu, LVMenu, Add, Rate, :LVRateMenu
Menu, LVMenu, Add
Menu, LVMenu, Add, Properties, ShowProperties
Menu, MyMenu, Add, %LVMenu%, :LVMenu
Gui, Menu, MyMenu
;------------------------------------------
; beim Wechsel der Sprache müssen die alten Menünamen gespeichert werden
oldMenuImportFile := MenuImportFile
oldMenuImportFolder := MenuImportFolder
oldMenuImportTitle := MenuImportTitle
oldLVMenu := LVMenu
oldtitel := MenulanguageTitel
LangHelp_showLangTrayMenu(possibleLangs, MenulanguageTitel)
LangHelp_showLangMenu(possibleLangs, MenulanguageTitel,"LVRateMenu")
LangHelp_showLangRadioMenu(possibleLangs, actualLang)
;------------------------------------------
Gui,Add, text, vOptionsLang w300, OptionsLang=hallo
Gui,Show,,Language - Sprache
Return
/*
;------------- minimum Version------------------
;Wenn die Sprache erst durch Neuladen verändert werden soll
;reicht das
updateLang:
IniWrite, %actualLang%, test.ini, lang, actualLang
reload
return
*/
;/*
updateLang:
;---this is up to yours ----------------------
; Hier müssen die eigenen Controls aktualisiert werden
IniWrite, %actualLang%, test.ini, lang, actualLang
If (oldMenuImportFile<>MenuImportFile)
Menu, ImportMenu, Rename, %oldMenuImportFile%,%MenuImportFile%
oldMenuImportFile:=MenuImportFile
If (oldMenuImportFolder<>MenuImportFolder)
Menu, ImportMenu, Rename, %oldMenuImportFolder%, %MenuImportFolder%
oldMenuImportFolder:=MenuImportFolder
If (oldMenuImportTitle<>MenuImportTitle)
Menu, Filemenu, Rename, %oldMenuImportTitle%, %MenuImportTitle%
oldMenuImportTitle:=MenuImportTitle
If (oldLVMenu<>LVMenu)
Menu,MyMenu,Rename,%oldLVMenu%,%LVMenu%
oldLVMenu=%LVMenu%
If (oldtitel<>MenulanguageTitel)
Menu,LVRateMenu,Rename,%oldtitel%,%MenulanguageTitel%
oldtitel=%MenulanguageTitel%
Return
;*/
importfolder:
msgbox, hallo %A_ThisMenu%
return
importfile:
msgbox, hallo %A_ThisMenu%
return
playpause:
msgbox, hallo %A_ThisMenu%
return
showproperties:
msgbox, hallo %A_ThisMenu%
return
rate5:
msgbox, hallo %A_ThisMenu%
return
rate4:
msgbox, hallo %A_ThisMenu%
return
rate3:
msgbox, hallo %A_ThisMenu%
return
rate2:
msgbox, hallo %A_ThisMenu%
return
rate1:
msgbox, hallo %A_ThisMenu%
return
deletetrack:
msgbox, hallo %A_ThisMenu%
return
playLVItem:
msgbox, hallo %A_ThisMenu%
return
exit:
msgbox, hallo %A_ThisMenu%
return
togglecheckshuffle:
msgbox, hallo %A_ThisMenu%
return
blank:
msgbox, hallo %A_ThisMenu%
return
stop:
msgbox, hallo %A_ThisMenu%
return
^o::
void:
msgbox, hallo %A_ThisMenu%
return
esc::
GuiEscape:
GuiClose:
ExitApp
Return
#include LangHelp.ahk
|
how it looks:
 |
|
| Back to top |
|
 |
Jero3n
Joined: 19 Jan 2007 Posts: 151
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|