Internationalization library for AutoHotKey programs.
npm install i18n-autohotkeyGlobal i18nService := New i18n(LanguageFolder, LanguageFile, [DevMode])
str := Translate("KeyName", [arg1, arg2, ...])
ini
[Strings]
HelloWorld=Hello world!
Greetings=Welcome in {1}.
`
Here's an example of a working script featuring i18n (it will work given you have the associated fr-FR.ini file in your language folder):
`AutoHotKey
#Include lib\i18n.ahk
MyAppName := "Sample Project"
Global i18nService := New i18n("i18n", "en-US")
MsgBox % Translate("HelloWorld")
MsgBox % Translate("Greetings", [MyAppName])
; You can dynamically change the language without reloading the program
i18nService := New i18n("i18n", "fr-FR")
MsgBox % Translate("HelloWorld")
MsgBox % Translate("Greetings", [MyAppName])
`
You can download this sample project on the releases page.
$3
Here is an example of a project using a GUI, multiline and imbricated translation (you download this sample project on the releases page).
`AutoHotKey
#Include lib\i18n.ahk
Global i18nService := New i18n("i18n", "en-US", True)
Gui, Add, Button, ,Switch Language
Gui, Add, Text, vTextGui w150,% Translate("TextGui")
Gui, Add, Button, ,Demo
Gui, Show, w300 h200
toggled := False
return
GetVar(var){
global
return %var%
}
ButtonSwitchLanguage:
If !toggled
lang := "fr-FR"
Else
lang := "en-US"
i18nService := New i18n("i18n", lang, True)
GuiControl, Text, TextGui, % Translate("TextGui")
toggled := !toggled
return
ButtonDemo:
; #1 - Basic translation
MsgBox,, % "#1", % Translate("Basic")
; #2a - Argument
TitleApp := "Translation Helper"
MsgBox,, % "#2a", % Translate("Greetings", [TitleApp])
; #2b - Example multiple arguments
colors := [Translate("Blue"), Translate("White"), Translate("Red")]
MsgBox,, % "#2b", % Translate("Flag", [colors[1], colors[2], colors[3]])
; #3 - Multiline
; To Do
; #4 - Example complex MsgBox
MsgBox, 48, % "#4 " Translate("ComplexTitle", [GetVar("TitleApp")]), % Translate("Complex", [colors[3], colors[1]])
return
F12::
ExitApp
return
``