The installer asks for the language before the keyboard, and Setup > Language (omarchy language en|zh) switches it later. Under zh_CN the menu reads its labels from omarchy-menu.zh-cn.jsonc, the shell from I18nZh.js through I18n.tr, and notifications are worded by their sender through omarchy-text, which reads the same table. User text is never translated.
39 lines
1.0 KiB
Bash
Executable File
39 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Print an Omarchy message in the session's language, with %1.. filled from the arguments
|
|
# omarchy:args=<english> [args...]
|
|
# omarchy:examples=omarchy-text "Sent to %1" phone
|
|
# omarchy:hidden=true
|
|
|
|
set -euo pipefail
|
|
|
|
if (($# < 1)); then
|
|
echo "Usage: omarchy-text <english> [args...]" >&2
|
|
exit 1
|
|
fi
|
|
|
|
text=$1
|
|
shift
|
|
|
|
# The shell's table is the one source: one JSON-encoded "english": "chinese" pair per line.
|
|
if [[ ${LANG:-} == zh_CN* ]]; then
|
|
translated=$(grep -E '^ ".*": ".*",?$' "$OMARCHY_PATH/shell/Commons/I18nZh.js" | sed 's/,$//' | paste -sd, |
|
|
sed 's/^/{/; s/$/}/' | jq -r --arg key "$text" '.[$key] // empty')
|
|
[[ -z $translated ]] || text=$translated
|
|
fi
|
|
|
|
# One pass over the template, so an argument that holds %2 is printed as given.
|
|
out=""
|
|
rest=$text
|
|
while [[ $rest =~ ^([^%]*)%(.)(.*)$ ]]; do
|
|
out+=${BASH_REMATCH[1]}
|
|
mark=${BASH_REMATCH[2]}
|
|
rest=${BASH_REMATCH[3]}
|
|
if [[ $mark == [1-9] ]] && ((mark <= $#)); then
|
|
out+=${!mark}
|
|
else
|
|
out+="%$mark"
|
|
fi
|
|
done
|
|
printf '%s\n' "$out$rest"
|