feat(i18n): add client translation workflow script

This commit is contained in:
moonrailgun
2026-07-19 23:50:37 +08:00
parent b4e60a32e1
commit 67314bb7a8
2 changed files with 61 additions and 0 deletions
Executable
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CLIENT_DIR="${SCRIPT_DIR}/src/client"
pnpm --dir "${CLIENT_DIR}" run translation:extract
pnpm --dir "${CLIENT_DIR}" run translation:scan
pnpm --dir "${CLIENT_DIR}" run translation:translate
+51
View File
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SCRIPT_PATH="${ROOT_DIR}/i18n.sh"
TMP_DIR="$(mktemp -d)"
FAKE_BIN="${TMP_DIR}/bin"
LOG_FILE="${TMP_DIR}/pnpm.log"
cleanup() {
rm -rf "${TMP_DIR}"
}
trap cleanup EXIT
mkdir -p "${FAKE_BIN}"
cat >"${FAKE_BIN}/pnpm" <<'STUB'
#!/usr/bin/env bash
printf '%s\n' "$*" >>"${PNPM_LOG_FILE}"
if [[ -n "${FAIL_ON_COMMAND:-}" && "$*" == *"${FAIL_ON_COMMAND}"* ]]; then
exit 42
fi
STUB
chmod +x "${FAKE_BIN}/pnpm"
run_wrapper() {
(cd "${TMP_DIR}" && PATH="${FAKE_BIN}:${PATH}" PNPM_LOG_FILE="${LOG_FILE}" "$@" "${SCRIPT_PATH}")
}
run_wrapper env
cat >"${TMP_DIR}/expected-success.log" <<EOF
--dir ${ROOT_DIR}/src/client run translation:extract
--dir ${ROOT_DIR}/src/client run translation:scan
--dir ${ROOT_DIR}/src/client run translation:translate
EOF
diff -u "${TMP_DIR}/expected-success.log" "${LOG_FILE}"
: >"${LOG_FILE}"
set +e
run_wrapper env FAIL_ON_COMMAND=translation:scan
exit_code=$?
set -e
[[ "${exit_code}" -eq 42 ]]
cat >"${TMP_DIR}/expected-failure.log" <<EOF
--dir ${ROOT_DIR}/src/client run translation:extract
--dir ${ROOT_DIR}/src/client run translation:scan
EOF
diff -u "${TMP_DIR}/expected-failure.log" "${LOG_FILE}"