Skip to content

Instantly share code, notes, and snippets.

@SummonHIM
Last active April 28, 2025 10:57
Show Gist options
  • Select an option

  • Save SummonHIM/13027aae9a97b0e4b798bab91d05763d to your computer and use it in GitHub Desktop.

Select an option

Save SummonHIM/13027aae9a97b0e4b798bab91d05763d to your computer and use it in GitHub Desktop.
Build Git for Windows locale file / 编译 Git for Windows 语言文件(Git for Windows 汉化脚本)

Build Git for Windows locale/language file (English readme)

Exec this command at Windows Git Bash Console.

sh -c "$(curl -fsSL https://gist.github.com/SummonHIM/13027aae9a97b0e4b798bab91d05763d/raw/build-git-locale.sh)"

For ^v2.44.0.windows.1

  1. Download gettext-x.xx.x-x-x86_64.pkg.tar.zst at https://packages.msys2.org/package/gettext
  2. Extract gettextx.xx.x-x-x86_64.pkg.tar.zst/usr to X:\Path\to\your\git\usr

编译 Git for Windows 语言文件 (简中说明)

请在 Windows 系统中的 Git Bash 控制台中执行该命令:

sh -c "$(curl -fsSL https://gist.github.com/SummonHIM/13027aae9a97b0e4b798bab91d05763d/raw/build-git-locale.sh)"

国内镜像:https://gitee.com/summonhim/build-git-locale.sh (国内镜像中有更详细的图文安装说明)

对于 v2.44.0.windows.1 及以后版本

  1. https://packages.msys2.org/package/gettext 中下载 gettext-x.xx.x-x-x86_64.pkg.tar.zst 文件
  2. 解压 gettextx.xx.x-x-x86_64.pkg.tar.zst 中的 /usr 文件夹至 X:\你的\Git\安装\文件夹\usr
  3. 在用户环境变量中添加 LANG=zh_CN.GB2312 以修复乱码问题

編譯 Git for Windows 語言文件 (繁中說明)

請在 Windows 系統中的 Git Bash 控制台中執行該指令:

sh -c "$(curl -fsSL https://gist.github.com/SummonHIM/13027aae9a97b0e4b798bab91d05763d/raw/build-git-locale.sh)"

對於 v2.44.0.windows.1 及以后版本

  1. https://packages.msys2.org/package/gettext 中下載 gettext-x.xx.x-x-x86_64.pkg.tar.zst 文件
  2. 解壓縮 gettextx.xx.x-x-x86_64.pkg.tar.zst 中的 /usr 資料夾至 X:\你的\Git\安裝\資料夾\usr
  3. 在使用者環境變數中加入 LANG=zh_TW.BIG5 以修復亂碼問題(未經測試,但思路是一致的)
#!/usr/bin/bash
if [[ $LANG =~ zh_CN ]]; then
langCloneFailed="错误:克隆失败…"
langBuilding="正在编译"
langBuildingto="至"
langDoneA="完成!你现在可以删除文件夹"
langDoneB="了。"
langUsingCustomRepo="使用自定义远程仓库:"
langCDTo="更换目录至:"
langBranchNotCompareA="错误:该存储库的分支与您的 git 版本不相符!"
langBranchNotCompareB="请删除现有文件夹并重试。"
langBuildFailed="错误:编译失败!"
langBuildError="编译出现错误!请检查相关日志输出。"
langPause="按任意键继续…"
elif [[ $LANG =~ zh_TW ]]; then
langCloneFailed="錯誤:複製失敗…"
langBuilding="正在編譯"
langBuildingto="至"
langDoneA="完成!你現在可以刪除資料夾"
langDoneB="了。"
langUsingCustomRepo="使用自訂遠端倉庫:"
langCDTo="更換目錄至:"
langBranchNotCompareA="錯誤:該儲存庫的分支與您的 git 版本不相符!"
langBranchNotCompareB="請刪除現有資料夾並重試。"
langBuildFailed="錯誤:編譯失敗…"
langBuildError="編譯出現錯誤!請檢查相關日誌輸出。"
langPause="按任意鍵繼續…"
else
langCloneFailed="Error: Cloning failed..."
langBuilding="Building"
langBuildingto="to"
langDoneA="Done! You can remove the folder"
langDoneB="now."
langUsingCustomRepo="Using custom repository: "
langCDTo="Change directory to "
langBranchNotCompareA="Error: This repository's branch not compare with your git version!"
langBranchNotCompareB='Please remove the existing folder and retry.'
langBuildFailed="Error: Build failed!"
langBuildError="Build locale file failed! Please check the log of output."
langPause="Press any key to continue..."
fi
if [ ! -d "git" ]; then
if [ $1 ]; then
echo "$langUsingCustomRepo$1"
{
git clone $1 --depth=1 -b v$(git --version | cut -d ' ' -f3) git
echo ""
} || {
echo ""
echo "$langCloneFailed"
exit 1
}
else
{
git clone https://github.com/git-for-windows/git.git --depth=1 -b v$(git --version | cut -d ' ' -f3) git
echo ""
} || {
echo ""
echo "$langCloneFailed"
exit 1
}
fi
fi
echo "$langCDTo$(readlink -f git)"
cd git
echo ""
if [ "v$(git --version | cut -d ' ' -f3)" == "$(git tag)" ]; then
buildError=0
for poFiles in $(ls po | grep ".po$" | sed 's/\.[^.]*$//'); do
{
echo "$langBuilding po/$poFiles.po $langBuildingto /mingw64/share/locale/$poFiles/LC_MESSAGES/git.mo..."
mkdir -p /mingw64/share/locale/$poFiles/LC_MESSAGES
msgfmt po/$poFiles.po -o /mingw64/share/locale/$poFiles/LC_MESSAGES/git.mo
} || {
echo "$langBuildError"
buildError=1
read -s -n1 -p "$langPause"
echo ""
}
done
echo ""
for guiPoFIles in $(ls git-gui/po | grep ".po$" | sed 's/\.[^.]*$//'); do
{
echo "$langBuilding git-gui/po/$guiPoFIles.po $langBuildingto /mingw64/share/git-gui/lib/msgs/$guiPoFIles.msg..."
mkdir -p /mingw64/share/git-gui/lib/msgs
msgfmt --statistics --tcl -l $guiPoFIles git-gui/po/$guiPoFIles.po -d /mingw64/share/git-gui/lib/msgs
} || {
echo "$langBuildError"
buildError=1
read -s -n1 -p "$langPause"
echo ""
}
done
echo ""
if [ $buildError == 1 ]; then
echo "$langBuildFailed"
else
echo "$langDoneA \"$(pwd -W | sed 's/[^.*]po$//')\" $langDoneB"
fi
else
echo ""
echo $langBranchNotCompareA
echo $langBranchNotCompareB
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment