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
+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"
|
||||
Reference in new issue
Block a user