UI languages and help (Mac version)
- Source layout
- Build, test and release
- UI languages and help (this page)
UI languages (Lang.swift)
UI strings are looked up with Lang in Sources/TeraCore/Lang.swift. There are two kinds of language files.
| Lookup | Language file | Used for |
|---|---|---|
Lang.t("Tera Term", "MENU_FILE_NEW", "新しい接続...") | upstream installer/release/lang_utf8/<lang>.lng (same sections and keys as upstream) | strings that upstream also has |
Lang.m("MENU_TOGGLE_MENUBAR", "メニューバーを開く") | the [Tera Term Mac] section of macos/Resources/lang/mac_<lang>.lng | Mac-only strings |
The last argument is the fallback text (in Japanese). Strings with %s, %d and so on take values after it (Lang.m("SETUP_INI_LOADED", "%s を読み込みました", name)).
Returned strings have Windows access keys ((&F), &F) and shortcut labels (\tAlt+N) removed, and \n becomes a newline. Use Lang.raw for the unmodified value.
Lookup order
- the upstream language file of the selected language (e.g.
ja_JP.lng) - the Mac language file of the selected language (e.g.
mac_ja_JP.lng) - the upstream English file (
en_US.lng) - the Mac English file (
mac_en_US.lng) - the fallback text in the call
Section and key names are case-insensitive. In the app, language files are read from Contents/Resources/lang; during development (swift build) from the source tree's macos/Resources/lang and installer/release/lang_utf8.
Choosing the language
The language is UILanguageFile in UserDefaults (same name as in upstream TERATERM.INI, e.g. ja_JP.lng). An upstream style value such as lang_utf8\ja_JP.lng also works; only the file name is used.
When it is empty (automatic), the macOS preferred languages are checked in order and the closest language file is chosen: one that matches the region (e.g. pt-BR → pt_BR.lng), otherwise one of the same language. Chinese uses zh_TW.lng for Traditional (Hant, TW, HK, MO) and zh_CN.lng otherwise. If nothing matches, English is used.
Changing the language posts Lang.didChange, and menus and the like are rebuilt.
Adding a string
- If an upstream language file already has a string with the same meaning, use it with
Lang.tand the upstream section and key. - Otherwise write
Lang.m("KEY", "Japanese text")and add the key to the[Tera Term Mac]section ofResources/lang/mac_ja_JP.lngandmac_en_US.lng. Please add it to the othermac_*.lngfiles as well (languages without it show English). - Leading and trailing spaces in language file values are dropped. If you need them, add them in code.
Adding a language
The selectable languages are the upstream language files in lang_utf8 (except Default.lng and mac_*.lng), named by each file's [Info] language=.
For a language upstream already has, create Resources/lang/mac_<lang>.lng (copy mac_en_US.lng and translate it; UTF-8) with an [Info] language= line and a [Tera Term Mac] section; scripts/bundle.sh puts it into the app.
A language upstream does not have needs an upstream language file first.
Help
The help is in macos/Resources/help-mac/{ja,en}. It is based on upstream doc/ja and doc/en, rewritten for the Mac, under the same BSD license as Tera Term.
When the UI language is Japanese the ja help is shown, otherwise the en help (HelpViewer.language). If that help is missing, the other one is used.
| File | Contents |
|---|---|
| html/ | The help pages. The classic table of contents is html/index.html |
| teraterm.hhp | The same hhp as upstream's CHM. Its [ALIAS] lines (HlpXxx=html\menu\xxx.html) map help IDs to pages (Shift_JIS) |
| modern-toc.json | The task-oriented table of contents on the left of the modern view |
| html/modern.html | The start page of the modern view |
scripts/bundle.sh copies these into Contents/Resources/help/{ja,en} and puts upstream teraterm/common/helpid.h at Contents/Resources/help/helpid.h. During development the help-mac folder in the source tree (or upstream doc if missing) is used.
Help IDs
Help buttons in dialogs and similar open pages by the same help IDs as upstream.
HelpViewer.openIndex() // contents (modern.html in the modern view) HelpViewer.open(topic: "HlpMenuSetupAdditionalTheme") // name from helpid.h HelpViewer.open(id: 43024) // number from helpid.h HelpViewer.open(relativePath: "html/menu/setup-font.html#xxx")
A name is resolved to a page through [ALIAS] in teraterm.hhp, and a number to a name through the #define lines in helpid.h. Unknown names open the contents (HlpIndex).
To open a new page by ID, add a line to [ALIAS] in teraterm.hhp.
Help images
To keep the app small, help images (*.png) are not bundled. When a page is shown and an image is missing locally, it is loaded from the same path in the upstream web manual (https://teratermproject.github.io/manual/5/<lang>/). Without a network connection only the images are missing.
So pages rewritten for the Mac must keep the same image paths as upstream.
Modern view (HelpModernStyle.swift)
The help window can switch between "Classic" and "Modern" (Modern by default; HelpStyleModern in UserDefaults). In the modern view the page HTML is unchanged; at display time a script applies the new look (system font, wider line spacing, dark mode, table of contents and search on the left).
- The left table of contents is
<lang>/modern-toc.json, in the form[{"t": heading, "items": [{"t": title, "p": path under html/}]}];pmay include a#anchor. Without the file, it is built from the classic contents (div.topicelements in html/index.html and the links under them). - The start page is html/modern.html (html/index.html if missing).
- When you add a page, list it in html/index.html, modern-toc.json and, if useful, modern.html.
Page encodings
Most pages that come from upstream are Shift_JIS (Japanese) or ASCII (English) with CRLF line endings. Keep the original encoding and line endings when you edit them. New Mac-only pages are UTF-8 (<meta charset="utf-8">). The modern view reads a page using its meta charset (UTF-8 if there is none, then Shift_JIS).