Internationalisation
Message ids are always English; translations live in locale/<lang>/LC_MESSAGES/shellkit.po.
Use
log_info "$(_t 'starting service')"
printf '%s\n' "$(_tn 'file' 'files' "$count")"
_t looks the id up in the current language and, when it finds nothing, returns the id unchanged -- a missing translation is never an error, it just degrades to English. _tn handles plurals; the exact forms come from msgstr[0] / msgstr[1] in the .po file.
How the language is chosen
In order: SHELLKIT_LANG → LC_ALL / LC_MESSAGES / LANG → default en. Setting SHELLKIT_NO_GETTEXT=1 disables lookup entirely, which is what you want when ruling out "is a translation causing this?".
Without SHELLKIT_LANG, gettext picks the language itself: LANGUAGE → LC_ALL → LC_MESSAGES → LANG. Note that LANGUAGE wins over LC_ALL -- that is gettext's rule, and it is left alone on purpose: changing it would mean changing the user's language behind their back.
Multiple domains and the fallback table
| Variable | What it does | Default |
|---|---|---|
SHELLKIT_I18N_DOMAIN | the message domain | ${TEXTDOMAIN:-shellkit} |
SHELLKIT_I18N_DIRS | colon-separated lookup directories | ${TEXTDOMAINDIR:-$SHELLKIT_HOME/locale} |
SHELLKIT_LANG | language directory name (zh_CN) | LC_ALL / LC_MESSAGES / LANG, else en |
With none of them set, _t behaves exactly as before.
Once they are set, the lookup order is:
- the pure-bash fallback table
<dir>/<lang>/messages/<domain>.sh; <dir>/<lang>/LC_MESSAGES/<domain>.mo, walking the directories in order and falling back to theshellkitdomain when the requested one has no catalogue;- the message id unchanged, when nothing matches.
The fallback table is a pure-bash function (one big case) generated by po/messages.sh and committed as locale/<lang>/messages/<domain>.sh. Its purpose is machines without gettext: macOS ships no gettext by default, so on those machines the .mo files are useless and this table is what produces translated output.
SHELLKIT_I18N_DOMAIN and SHELLKIT_I18N_DIRS may be set after bootstrap -- the tables are loaded lazily for the current (language, domain, directories), so a later change takes effect on the next lookup.
Regenerate
bash po/messages.sh
One command, three steps: xgettext extracts message ids → msgmerge merges them into every .po → msgfmt compiles the .mo files. To check without writing:
bash po/messages.sh --check
On a machine without xgettext, --check skips instead of failing. macOS does not ship gettext by default, and treating "the tool is missing" as "the translations are stale" would red-flag a lot of innocent machines.
Two deliberate choices
1. --no-location when extracting, and relative paths
By default a pot records location comments such as #: lib/core/net.sh:42. That has two consequences:
- regenerating on another machine, or from another absolute path, rewrites the whole pot;
- changing one line shifts every line number below it, and rewrites the whole pot again.
Neither diff carries meaning, yet both keep the "is the pot current?" gate red forever. So extraction runs with --no-location, and xgettext is fed relative paths from the repository root.
2. No placeholders in message ids
# no: a message id containing a concrete value can never match a translation, it just leaves a dead key
log_info "$(_t 'deploying to $host')"
# yes: the value is data, the message id is the sentence
log_info "$(_t 'deploying to'): $host"
An interpolated id is different on every call; xgettext extracts the literal from the one call it saw, and no translation table can contain it.
By the same reasoning, the command description passed to cli_cmd is not wrapped in _t: describing the project's own commands is the project's business, and wrapping it only stuffs dead keys into a shared library's table.
Add a language
mkdir -p locale/de/LC_MESSAGES
cp locale/en/LC_MESSAGES/shellkit.po locale/de/LC_MESSAGES/shellkit.po
bash po/messages.sh
Empty msgstr values in locale/en are intentional: English falls back to the message id, so there is no point maintaining an English table that mirrors the code.