From 5dabcc34f7a804a5abac9731c069ba8d09034639 Mon Sep 17 00:00:00 2001 From: esowt Date: Sun, 2 Aug 2026 23:46:17 +0800 Subject: [PATCH] Improve installer onboarding --- scripts/install.ps1 | 41 ++++++++++++++++++++++++++++++++++----- scripts/install.sh | 47 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 77 insertions(+), 11 deletions(-) diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 5cd980b..b9c2458 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -27,6 +27,19 @@ function Get-RequestHeaders { return $headers } +function Test-ChineseInstallLanguage { + $preference = if (-not [string]::IsNullOrWhiteSpace($env:DOC7_LANG)) { + $env:DOC7_LANG + } + else { + [Globalization.CultureInfo]::CurrentUICulture.Name + } + + return $preference -match '^zh(?:[-_]|$)' +} + +$useChinese = Test-ChineseInstallLanguage + if ($env:OS -ne "Windows_NT") { Stop-Install "this installer supports Windows only" } @@ -92,7 +105,12 @@ $extractDir = Join-Path $tempDir "extract" try { New-Item -ItemType Directory -Path $tempDir -Force | Out-Null - Write-Host "Downloading doc7 $Version for Windows/$Architecture..." + if ($useChinese) { + Write-Host "正在下载 doc7 $Version(Windows/$Architecture)……" + } + else { + Write-Host "Downloading doc7 $Version for Windows/$Architecture..." + } $archiveRequest = @{ Uri = "$releaseUrl/$assetName" Headers = $headers @@ -169,10 +187,23 @@ try { } $env:Path = "$normalizedInstallDir;$($env:Path)" - & (Join-Path $normalizedInstallDir "doc7.exe") version - Write-Host "Installed directory: $normalizedInstallDir" - Write-Host "Next: doc7 setup" - Write-Host "Then: doc7 " + $installedExecutable = Join-Path $normalizedInstallDir "doc7.exe" + & $installedExecutable version | Out-Null + + if ($useChinese) { + Write-Host "doc7 已安装:$installedExecutable" + Write-Host "" + Write-Host "安装完成。下面是 doc7 的使用说明:" + Write-Host "" + } + else { + Write-Host "Installed executable: $installedExecutable" + Write-Host "" + Write-Host "Installation complete. Here is how to use doc7:" + Write-Host "" + } + + & $installedExecutable } finally { if (Test-Path -LiteralPath $tempDir) { diff --git a/scripts/install.sh b/scripts/install.sh index 78013c0..92f2640 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -2,6 +2,25 @@ set -euo pipefail +detect_install_language() { + local preference + + preference="${DOC7_LANG:-}" + if [[ -z "${preference}" ]] && [[ "$(uname -s)" == "Darwin" ]] && command -v defaults >/dev/null 2>&1; then + preference="$(defaults read -g AppleLanguages 2>/dev/null | awk -F'"' 'NF >= 2 { print $2; exit }' || true)" + fi + if [[ -z "${preference}" ]]; then + preference="${LC_ALL:-${LC_MESSAGES:-${LANG:-}}}" + fi + + case "${preference}" in + [zZ][hH] | [zZ][hH][-_]*) printf 'zh-CN\n' ;; + *) printf 'en\n' ;; + esac +} + +INSTALL_LANGUAGE="$(detect_install_language)" + fail() { printf 'doc7 installer: %s\n' "$*" >&2 exit 1 @@ -114,7 +133,11 @@ cleanup() { } trap cleanup EXIT -printf 'Downloading doc7 %s for %s/%s...\n' "${VERSION}" "${OS}" "${ARCH}" +if [[ "${INSTALL_LANGUAGE}" == "zh-CN" ]]; then + printf '正在下载 doc7 %s(%s/%s)……\n' "${VERSION}" "${OS}" "${ARCH}" +else + printf 'Downloading doc7 %s for %s/%s...\n' "${VERSION}" "${OS}" "${ARCH}" +fi curl --fail --silent --show-error --location \ --output "${ARCHIVE_PATH}" "${RELEASE_URL}/${ASSET_NAME}" curl --fail --silent --show-error --location \ @@ -138,16 +161,28 @@ if [[ -f "${README_PATH}" ]]; then install -m 0644 "${README_PATH}" "${SHARE_DIR}/README.txt" fi -"${INSTALL_DIR}/doc7" version -printf 'Installed executable: %s\n' "${INSTALL_DIR}/doc7" +"${INSTALL_DIR}/doc7" version >/dev/null +if [[ "${INSTALL_LANGUAGE}" == "zh-CN" ]]; then + printf 'doc7 已安装:%s\n' "${INSTALL_DIR}/doc7" +else + printf 'Installed executable: %s\n' "${INSTALL_DIR}/doc7" +fi case ":${PATH}:" in *":${INSTALL_DIR}:"*) ;; *) - printf 'Add this directory to PATH before opening a new shell:\n' + if [[ "${INSTALL_LANGUAGE}" == "zh-CN" ]]; then + printf '请把这个目录加入 PATH,然后重新打开终端:\n' + else + printf 'Add this directory to PATH before opening a new shell:\n' + fi printf ' export PATH="%s:$PATH"\n' "${INSTALL_DIR}" ;; esac -printf 'Next: doc7 setup\n' -printf 'Then: doc7 \n' +if [[ "${INSTALL_LANGUAGE}" == "zh-CN" ]]; then + printf '\n安装完成。下面是 doc7 的使用说明:\n\n' +else + printf '\nInstallation complete. Here is how to use doc7:\n\n' +fi +"${INSTALL_DIR}/doc7"