Switch regions from Setup > Region and show Chinese menu labels under zh_CN
This commit is contained in:
1 parent
56c8344fd2
commit
5f6c803b21
12 files changed
+408
-18
No files matched your search
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
||||
|
||||
require_command node
|
||||
|
||||
node - "$ROOT" <<'JS'
|
||||
const fs = require('fs')
|
||||
const root = process.argv[2]
|
||||
const model = require(`${root}/shell/plugins/menu/MenuModel.js`)
|
||||
const read = name => model.parseMenuJsonc(fs.readFileSync(`${root}/default/omarchy/${name}`, 'utf8'))
|
||||
const fail = message => { console.error(`not ok - ${message}`); process.exit(1) }
|
||||
|
||||
const defaults = read('omarchy-menu.jsonc')
|
||||
const chinese = read('omarchy-menu.zh-cn.jsonc')
|
||||
const byId = Object.fromEntries(defaults.map(item => [item.id, item]))
|
||||
|
||||
const unknown = chinese.filter(item => !byId[item.id]).map(item => item.id)
|
||||
if (unknown.length) fail(`every Chinese label names a shipped menu id: ${unknown}`)
|
||||
const extra = chinese.filter(item => item.declared.some(key => key !== 'label' && key !== 'title')).map(item => item.id)
|
||||
if (extra.length) fail(`the Chinese overlay only retitles rows: ${extra}`)
|
||||
console.log('ok - the Chinese overlay only retitles shipped menu rows')
|
||||
|
||||
const user = model.parseMenuJsonc('{"system.lock": {"label": "Mine"}}')
|
||||
const merged = model.mergeMenuSources(defaults, chinese.concat(user)).items
|
||||
for (const item of defaults) {
|
||||
const result = merged[item.id]
|
||||
const zh = chinese.find(entry => entry.id === item.id)
|
||||
for (const key of ['action', 'when', 'checked', 'disabled', 'target', 'provider', 'kind', 'icon', 'parent']) {
|
||||
if (JSON.stringify(result[key]) !== JSON.stringify(item[key])) fail(`${item.id} keeps its ${key} under the Chinese overlay`)
|
||||
}
|
||||
if (item.id !== 'system.lock' && zh && zh.declared.includes('label') && result.label !== zh.label) fail(`${item.id} shows its Chinese label`)
|
||||
}
|
||||
if (merged['system.lock'].label !== 'Mine') fail('a user extension still overrides the Chinese label')
|
||||
if (merged['system.reboot'].label !== '重启' || merged['install.china.wechat'].label !== '微信') fail('Chinese labels reach the merged menu')
|
||||
console.log('ok - Chinese labels replace only the label, and user extensions still win')
|
||||
JS
|
||||
|
||||
grep -qF 'root.localeMenuItems.concat(root.userMenuItems)' "$ROOT/shell/plugins/menu/Menu.qml" &&
|
||||
grep -qF 'startsWith("zh_CN") ? omarchyPath + "/default/omarchy/omarchy-menu.zh-cn.jsonc"' "$ROOT/shell/plugins/menu/Menu.qml" ||
|
||||
fail "the menu loads the Chinese overlay under zh_CN, beneath the user extension"
|
||||
pass "the menu loads the Chinese overlay under zh_CN, beneath the user extension"
|
||||
@@ -62,9 +62,10 @@ assertDeepEqual(
|
||||
aliases: ['theme'],
|
||||
when: '',
|
||||
checked: '',
|
||||
disabled: ''
|
||||
disabled: '',
|
||||
declared: ['label', 'aliases', 'description', 'action']
|
||||
},
|
||||
'menu normalizes parsed items'
|
||||
'menu normalizes parsed items and records what the file declared'
|
||||
)
|
||||
|
||||
const user = [
|
||||
@@ -76,6 +77,16 @@ assertEqual(merged.items['style.theme'].label, 'Theme picker', 'menu user entrie
|
||||
assertEqual(merged.items['style.theme'].order, 2, 'menu preserves original order on override')
|
||||
assert(merged.items.root, 'menu injects root when merging sources')
|
||||
|
||||
const retitled = menu.mergeMenuSources(
|
||||
menu.parseMenuJsonc('{"apps": {"icon":"A","label":"Apps","provider":"apps"}, "apps.go": {"label":"Go","action":"run-go"}}'),
|
||||
menu.parseMenuJsonc('{"apps": {"label":"应用"}, "apps.go": {"label":"出发"}}')
|
||||
)
|
||||
assertEqual(retitled.items['apps'].provider, 'apps', 'menu keeps the provider when a user entry only retitles')
|
||||
assertEqual(retitled.items['apps'].icon, 'A', 'menu keeps the icon when a user entry only retitles')
|
||||
assertEqual(retitled.items['apps.go'].action, 'run-go', 'menu keeps the action when a user entry only retitles')
|
||||
assertEqual(retitled.items['apps.go'].kind, 'action', 'menu keeps the kind when a user entry only retitles')
|
||||
assertEqual(retitled.items['apps.go'].label, '出发', 'menu applies the user retitle')
|
||||
|
||||
assertEqual(menu.slugify('Power Saver!'), 'power-saver', 'menu slugifies provider rows')
|
||||
assertEqual(menu.pathFor(merged.items, 'style.theme'), 'Style › Theme picker', 'menu builds item paths')
|
||||
assertEqual(menu.parentPathFor(merged.items, 'style.theme'), 'Style', 'menu builds parent paths')
|
||||
@@ -286,6 +297,14 @@ assert(
|
||||
'menu always exposes every supported browser, terminal, and editor under Defaults'
|
||||
)
|
||||
assert(!defaultById['install.ai.crush'], 'menu removes Crush from Install > AI')
|
||||
const regionEntries = defaultItems.filter(item => item.parent === 'setup.region')
|
||||
assert(
|
||||
regionEntries.map(item => item.label).join('\0') === 'Global\0China'
|
||||
&& regionEntries.every(item => item.checked.includes(`== \"${item.label}\"`) && !item.when)
|
||||
&& defaultById['setup.region.global'].action.includes('omarchy-region global')
|
||||
&& defaultById['setup.region.china'].action.includes('omarchy-region china'),
|
||||
'menu offers Global and China under Setup > Region'
|
||||
)
|
||||
// Software you already have keeps its place in Install, dimmed rather than
|
||||
// dropped, so the list reads as a catalog of what Omarchy can install.
|
||||
// Chromium Account is the sole Install row with anything left to hide for, so
|
||||
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
||||
|
||||
test_tmp=$(mktemp -d)
|
||||
trap 'rm -rf "$test_tmp"' EXIT
|
||||
|
||||
root="$test_tmp/root" sandbox="$test_tmp/omarchy" calls="$test_tmp/calls"
|
||||
mkdir -p "$root/etc/pacman.d" "$sandbox/bin" "$sandbox/install/config" "$sandbox/default/region" "$test_tmp/bin" "$test_tmp/home"
|
||||
cp -r "$ROOT/default/region/china" "$sandbox/default/region/"
|
||||
rewrite() { sed -e "s|/etc/|$root/etc/|g" -e "s| /\\.cargo/| $root/.cargo/|g" "$1" >"$2"; chmod +x "$2"; }
|
||||
rewrite "$ROOT/install/config/region.sh" "$sandbox/install/config/region.sh"
|
||||
rewrite "$ROOT/bin/omarchy-region" "$sandbox/bin/omarchy-region"
|
||||
|
||||
for command in pacman omarchy-pkg-add locale-gen rime-ice-installer omarchy-setup-claude-api; do
|
||||
printf '#!/bin/bash\necho "%s $*" >>"%s"\n' "$command" "$calls" >"$test_tmp/bin/$command"
|
||||
done
|
||||
printf '#!/bin/bash\n[[ $1 == env ]] && shift\nexec env "$@"\n' >"$test_tmp/bin/sudo"
|
||||
chmod +x "$test_tmp/bin"/*
|
||||
export PATH="$test_tmp/bin:$sandbox/bin:$PATH" OMARCHY_PATH="$sandbox" HOME="$test_tmp/home"
|
||||
|
||||
cp "$ROOT/default/pacman/pacman-stable.conf" "$root/etc/pacman.conf"
|
||||
cp "$ROOT/default/pacman/mirrorlist-stable" "$root/etc/pacman.d/mirrorlist"
|
||||
printf '#zh_CN.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\n' >"$root/etc/locale.gen"
|
||||
printf 'LANG=en_US.UTF-8\n' >"$root/etc/locale.conf"
|
||||
|
||||
china_conf=$(sed -f "$ROOT/default/region/china/pacman.sed" "$ROOT/default/pacman/pacman-stable.conf")
|
||||
china_mirrors=$(sed -f "$ROOT/default/region/china/pacman.sed" "$ROOT/default/pacman/mirrorlist-stable")
|
||||
|
||||
omarchy-region china >/dev/null
|
||||
[[ $(<"$root/etc/pacman.conf") == "$china_conf" && $(<"$root/etc/pacman.d/mirrorlist") == "$china_mirrors" ]] ||
|
||||
fail "switching to China lists the .cn mirrors first"
|
||||
[[ $(omarchy-region) == "China" && $(<"$root/etc/locale.conf") == "LANG=zh_CN.UTF-8" ]] || fail "switching to China records it and sets the language"
|
||||
[[ $(<"$calls") == $'pacman -Sy\nomarchy-pkg-add fcitx5-configtool fcitx5-rime librime opencc rime-ice-installer\nlocale-gen \nrime-ice-installer --yes' ]] ||
|
||||
fail "China syncs the .cn databases before installing Rime, then sets Rime Ice up" "$(<"$calls")"
|
||||
pass "switching to China sets mirrors, language and Rime Ice"
|
||||
|
||||
: >"$calls"
|
||||
mkdir -p "$HOME/.local/share/fcitx5/rime" && touch "$HOME/.local/share/fcitx5/rime/rime_ice.schema.yaml"
|
||||
omarchy-region china >/dev/null
|
||||
[[ $(<"$root/etc/pacman.conf") == "$china_conf" && $(<"$root/etc/pacman.d/mirrorlist") == "$china_mirrors" ]] ||
|
||||
fail "switching to China twice adds no second .cn line"
|
||||
grep -q '^rime-ice-installer' "$calls" && fail "an existing Rime Ice setup is not redone"
|
||||
pass "switching to China again changes nothing it already did"
|
||||
|
||||
: >"$calls"
|
||||
omarchy-region global >/dev/null
|
||||
[[ $(<"$root/etc/pacman.conf") == "$(<"$ROOT/default/pacman/pacman-stable.conf")" && $(<"$root/etc/pacman.d/mirrorlist") == "$(<"$ROOT/default/pacman/mirrorlist-stable")" ]] ||
|
||||
fail "switching to Global drops exactly the .cn mirrors"
|
||||
[[ $(omarchy-region) == "Global" && $(<"$root/etc/locale.conf") == "LANG=en_US.UTF-8" ]] || fail "switching to Global records it and restores English"
|
||||
[[ $(<"$calls") == $'pacman -Sy\nomarchy-setup-claude-api --remove' ]] || fail "Global removes the Claude Code third-party API and keeps Rime" "$(<"$calls")"
|
||||
[[ -f $HOME/.local/share/fcitx5/rime/rime_ice.schema.yaml ]] || fail "Global keeps the input method"
|
||||
pass "switching to Global restores mirrors and language, keeps Rime, removes the Claude API setup"
|
||||
|
||||
if output=$(omarchy-region mars 2>&1); then
|
||||
fail "an unknown region is refused" "$output"
|
||||
fi
|
||||
pass "an unknown region is refused"
|
||||
@@ -58,7 +58,7 @@ pass "an unknown region fails and names the file and value"
|
||||
stub_bin="$test_tmp/bin"
|
||||
calls="$test_tmp/calls"
|
||||
mkdir -p "$stub_bin"
|
||||
for command in omarchy-pkg-add rime-ice-installer; do
|
||||
for command in omarchy-pkg-add rime-ice-installer locale-gen; do
|
||||
printf '#!/bin/bash\necho "%s $*" >>"%s"\n' "$command" "$calls" >"$stub_bin/$command"
|
||||
done
|
||||
printf '#!/bin/bash\necho "$STUB_REGION"\n' >"$stub_bin/omarchy-region"
|
||||
@@ -69,12 +69,17 @@ region_setup="$test_tmp/region.sh"
|
||||
root="$test_tmp/root"
|
||||
sed -e "s|/etc/|$root/etc/|g" -e "s| /\.cargo/| $root/.cargo/|g" "$ROOT/install/config/region.sh" >"$region_setup"
|
||||
export OMARCHY_PATH="$ROOT"
|
||||
mkdir -p "$root/etc"
|
||||
printf '#zh_CN.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\n' >"$root/etc/locale.gen"
|
||||
printf 'LANG=en_US.UTF-8\nLC_TIME=en_DK.UTF-8\n' >"$root/etc/locale.conf"
|
||||
|
||||
: >"$calls"
|
||||
OMARCHY_REGION=china bash -e "$region_setup"
|
||||
[[ $(<"$root/etc/omarchy/region") == "china" ]] || fail "install records the China region"
|
||||
[[ $(<"$calls") == "omarchy-pkg-add fcitx5-configtool fcitx5-rime librime opencc rime-ice-installer" ]] ||
|
||||
fail "China installs the Rime input method packages" "$(<"$calls")"
|
||||
[[ $(<"$calls") == $'omarchy-pkg-add fcitx5-configtool fcitx5-rime librime opencc rime-ice-installer\nlocale-gen ' ]] ||
|
||||
fail "China installs the Rime input method packages and generates the Chinese locale" "$(<"$calls")"
|
||||
[[ $(<"$root/etc/locale.gen") == $'zh_CN.UTF-8 UTF-8\nen_US.UTF-8 UTF-8' ]] || fail "China enables zh_CN in locale.gen"
|
||||
[[ $(<"$root/etc/locale.conf") == $'LANG=zh_CN.UTF-8\nLC_TIME=en_DK.UTF-8' ]] || fail "China sets LANG and keeps other locale settings" "$(<"$root/etc/locale.conf")"
|
||||
for package in fcitx5-configtool fcitx5-rime librime opencc rime-ice-installer; do
|
||||
grep -qx "$package" "$ROOT/install/omarchy-other.packages" || fail "the ISO mirror carries $package"
|
||||
done
|
||||
@@ -90,6 +95,12 @@ pass "China links the developer mirror drop-ins"
|
||||
OMARCHY_REGION=global bash -e "$region_setup"
|
||||
[[ ! -e $root/etc/omarchy/region ]] || fail "install records Global by leaving no region file"
|
||||
[[ ! -s $calls ]] || fail "Global installs no input method packages" "$(<"$calls")"
|
||||
[[ $(<"$root/etc/locale.conf") == $'LANG=en_US.UTF-8\nLC_TIME=en_DK.UTF-8' ]] || fail "Global turns a Chinese LANG back to English" "$(<"$root/etc/locale.conf")"
|
||||
printf 'LANG=de_DE.UTF-8\n' >"$root/etc/locale.conf"
|
||||
OMARCHY_REGION=global bash -e "$region_setup"
|
||||
[[ $(<"$root/etc/locale.conf") == "LANG=de_DE.UTF-8" ]] || fail "Global leaves a language China did not set"
|
||||
printf 'LANG=en_US.UTF-8\n' >"$root/etc/locale.conf"
|
||||
pass "the region sets the language and Global only undoes Chinese"
|
||||
[[ ! -e $root/etc/environment.d/90-omarchy-china.conf && ! -e $root/.cargo/config.toml && ! -e $root/etc/gemrc ]] ||
|
||||
fail "Global removes the developer mirror drop-ins"
|
||||
pass "Global removes the developer mirror drop-ins"
|
||||
|
||||
Reference in new issue
Block a user