Word parameterized messages at the sender with omarchy-text and translate only exact text in the shell
This commit is contained in:
1 parent
619979a716
commit
051952600d
38 files changed
+198
-156
No files matched your search
@@ -5,6 +5,12 @@ source "$(dirname "$0")/base-test.sh"
|
||||
require_command jq
|
||||
require_command python3
|
||||
|
||||
# The collector words its diagnostics through omarchy-text.
|
||||
text_bin=$(mktemp -d)
|
||||
trap 'rm -rf "$text_bin"' EXIT
|
||||
ln -s "$ROOT/bin/omarchy-text" "$text_bin/omarchy-text"
|
||||
export PATH="$text_bin:$PATH"
|
||||
|
||||
# probe_limits reaches Anthropic, so the reader that interprets its answer is
|
||||
# exercised on its own: the collector loads as a module, and a recorded payload
|
||||
# stands in for the response.
|
||||
@@ -112,7 +118,7 @@ pass "Claude collector keeps Max multipliers and plain plan names"
|
||||
# is still good. Drive collect_limits over a planted cache with the network
|
||||
# unreachable, so nothing but the credential state decides the answer.
|
||||
CACHE_HOME=$(mktemp -d)
|
||||
trap 'rm -rf "$CACHE_HOME"' EXIT
|
||||
trap 'rm -rf "$CACHE_HOME" "$text_bin"' EXIT
|
||||
|
||||
collect_limits() {
|
||||
COLLECTOR="$ROOT/bin/omarchy-agent-usage-claude" TOKEN="$1" EXPIRES_AT="$2" \
|
||||
|
||||
@@ -31,7 +31,7 @@ assert(!/opacity: stale \?/.test(panelSource) && /I18n\.tr\("Last updated %1 ago
|
||||
assert(/onPickingChanged: resetKeys\(\)/.test(panelSource), 'the cursor starts over when the agent list comes or goes')
|
||||
assert(!/t === "a" \|\| t === "A"/.test(panelSource), 'adding an account has no hotkey; the + is the way in')
|
||||
assert(/if \(!accounts\[a\]\.active\) \{/.test(panelSource) && /if \(row\.length > 0\) rows\.push\(row\)/.test(panelSource), 'the active account with nothing to fix is not a keyboard stop')
|
||||
assert(/text: section\.provider \? I18n\.trMessage\(String\(section\.provider\.authHelpText \|\| section\.provider\.usageStatusText \|\| ""\)\) : ""/.test(panelSource), 'the trouble line falls back to the usage status when a record has no auth help')
|
||||
assert(/text: section\.provider \? I18n\.tr\(String\(section\.provider\.authHelpText \|\| section\.provider\.usageStatusText \|\| ""\)\) : ""/.test(panelSource), 'the trouble line falls back to the usage status when a record has no auth help')
|
||||
const mainSource = fs.readFileSync(root + '/shell/plugins/agents/Main.qml', 'utf8')
|
||||
assert(/var from = Math\.min\(0\.8, \(threshold - 15\) \/ 100\)/.test(mainSource), 'faster checks start 15 points below the switch threshold')
|
||||
assert(/rows\.push\(\[\{ kind: "provider", index: p \}\]\)/.test(panelSource), "every agent's header is a keyboard stop")
|
||||
|
||||
@@ -11,6 +11,7 @@ trap 'rm -rf "$TMPDIR"' EXIT
|
||||
|
||||
STUB_DIR="$TMPDIR/stub"
|
||||
mkdir -p "$STUB_DIR"
|
||||
ln -s "$ROOT/bin/omarchy-text" "$STUB_DIR/omarchy-text"
|
||||
|
||||
# The picker reads the plugin list from omarchy-plugin-list and hands what it
|
||||
# decided to a verb-specific command, so stubbing both ends shows which plugin
|
||||
|
||||
@@ -137,7 +137,7 @@ assertEqual(
|
||||
// belongs in the logic module, where the strip runs after it.
|
||||
const cardQml = fs.readFileSync(path.join(root, 'shell/plugins/notifications/components/NotificationCard.qml'), 'utf8')
|
||||
assert(
|
||||
/readonly property string styledBody: NotificationLogic\.styledBody\(I18n\.trMessage\(body\), app, appIcon\)/.test(cardQml),
|
||||
/readonly property string styledBody: NotificationLogic\.styledBody\(I18n\.tr\(body\), app, appIcon\)/.test(cardQml),
|
||||
'the notification card renders the body that was stripped after the newline rewrite'
|
||||
)
|
||||
assert(
|
||||
|
||||
@@ -10,7 +10,7 @@ const vm = require('vm')
|
||||
|
||||
const source = fs.readFileSync(path.join(root, 'shell/Commons/I18nZh.js'), 'utf8').replace('.pragma library', '')
|
||||
const context = {}
|
||||
vm.runInNewContext(source + '\nthis.table = table; this.templates = templates', context)
|
||||
vm.runInNewContext(source + '\nthis.table = table', context)
|
||||
const table = context.table
|
||||
|
||||
const files = []
|
||||
@@ -40,11 +40,33 @@ for (const file of files) {
|
||||
}
|
||||
}
|
||||
assert(calls > 300, 'the shell routes its text through I18n.tr', `found ${calls} calls`)
|
||||
const missingTemplates = Array.from(context.templates).filter(t => !(t in table))
|
||||
assert(missingTemplates.length === 0, 'every message template has a Chinese entry', missingTemplates.join('\n'))
|
||||
|
||||
// Senders translate messages that carry a name or number with omarchy-text, or text() in Python.
|
||||
const senders = []
|
||||
for (const entry of fs.readdirSync(path.join(root, 'bin'), { withFileTypes: true })) {
|
||||
if (!entry.isFile()) continue
|
||||
const name = entry.name
|
||||
const text = fs.readFileSync(path.join(root, 'bin', name), 'utf8')
|
||||
for (const match of text.matchAll(/(?:omarchy-text\s+|\btext\(\s*)"((?:[^"\\]|\\.)*)"/g)) {
|
||||
if (match[1].includes('$')) continue
|
||||
senders.push([name, JSON.parse('"' + match[1] + '"')])
|
||||
}
|
||||
}
|
||||
assert(senders.length > 40, 'senders translate their parameterized messages', `found ${senders.length}`)
|
||||
const unsent = senders.filter(([, key]) => !(key in table)).map(([file, key]) => `bin/${file}: ${key}`)
|
||||
assert(unsent.length === 0, 'every sender message has a Chinese entry', unsent.join('\n'))
|
||||
assert(missing.length === 0, 'every I18n.tr text has a Chinese entry', missing.join('\n'))
|
||||
|
||||
const placeholders = s => (s.match(/%\d/g) || []).sort().join(',')
|
||||
const mismatched = Object.keys(table).filter(key => placeholders(key) !== placeholders(table[key]))
|
||||
assert(mismatched.length === 0, 'every Chinese entry keeps its English placeholders', mismatched.join('\n'))
|
||||
JS
|
||||
|
||||
text=$ROOT/bin/omarchy-text
|
||||
[[ $(OMARCHY_PATH=$ROOT LANG=zh_CN.UTF-8 "$text" "Sent to %1" "phone %2") == "已发送给 phone %2" ]] ||
|
||||
fail "omarchy-text translates and fills %1 in one pass"
|
||||
[[ $(OMARCHY_PATH=$ROOT LANG=en_US.UTF-8 "$text" "Battery is down to %1%" 9) == "Battery is down to 9%" ]] ||
|
||||
fail "omarchy-text keeps English and a literal % outside zh_CN"
|
||||
[[ $(OMARCHY_PATH=$ROOT LANG=zh_CN.UTF-8 "$text" "Unknown 50% of %1" x) == "Unknown 50% of x" ]] ||
|
||||
fail "omarchy-text passes an unknown message through"
|
||||
pass "omarchy-text translates by exact key and fills arguments in one pass"
|
||||
@@ -10,6 +10,7 @@ trap cleanup EXIT
|
||||
|
||||
downloads="$WORKDIR/downloads"
|
||||
mkdir -p "$WORKDIR/bin" "$downloads" "$WORKDIR/outbox"
|
||||
ln -s "$ROOT/bin/omarchy-text" "$WORKDIR/bin/omarchy-text"
|
||||
printf 'mine' >"$downloads/unrelated.txt"
|
||||
|
||||
# Stands in for the daemon handing over whatever is waiting in the inbox. A
|
||||
|
||||
Reference in new issue
Block a user