message := sT(section, key, default := "ERROR", args := "", langPath := "")
Looks up a string in the active language file and does variable expansion.
;MyScript.ahk
MyGui.Title := sT("gui", "title", "/My App v%ver%", {ver:"2.0"})
MyGui.Add("Edit", "w400 r6", sT("welcome", "[section]"))
MsgBox sT("errors", "bad_path", "/File not found - %path%", {path:name})
;MyScript-[en].lang
[gui]
title = My App v%ver%
[welcome]
OneLocale provides an easier way to support multiple user-interface \w
languages in AutoHotkey.\n
Even if you don’t plan to support multiple languages, the way OneLocale \w
helps distinguish user-interface text from other string literals in \w
your code is valuable for code maintenance.
; in the special [errors] section, the key is shown verbatim
; before the translated message
[errors]
bad_path = File not found - %path%
| Sequence | Result | Note |
|---|---|---|
\t |
Tab | |
\n |
Line feed | leading space after it is stripped |
\w |
Remove newline | lets the GUI control word-wrap |
\z |
Comment to translator | text after \z is ignored |
\% |
Literal % |
|
\\ |
Literal \ |
Standard AutoHotkey backtick escapes are allowed too.
Save .lang files as UTF-16-LE with BOM – that’s the only encoding that works reliably.
{String} sSection - section name
{String} sKey - key name
{String} sDefault - text to use if lookup fails
sDefault is useful during development as temporary text until a .LANG file can be created)sDefault is unset, sT will throw errors - good for debugging but NOT for production{Object} args - optional names and values: {book:"HHGTTG", answer:42}
{String} langPath - if not empty, overrides g_lang_path as the path of the .LANG file
OneLocale_BakerGui app.#Include the generated file in your script.lang_id is “zh-cn”, generated function will be OneLocale_BuildMap_zh_cn()The .LANG file (or Map) may list a set of extender files (or maps) via an optional Extenders section. If the requested message is not found in the main .LANG file (or map), this function looks into the extenders. Extenders are listed in a special section (or key) named :extenders:.
This feature is helpful when you have .LANG data that is used in multiple projects, such as a dialog box (for example, OneLocaleDlg_Dialog)
Finally, if the search is exhausted, sDefault is returned,
sPath
\\?\ (long name enable) prefixed paths are supported,
and are added if needed on long paths.sDefault is returned; if there is no sDefault, a catchable Error is thrown.Back to README