diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..12844cf98 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +# bash 脚本必须保持 LF 行尾(CRLF 会导致解析问题) +.githooks/pre-commit text eol=lf +test/*.sh text eol=lf diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 000000000..a2966b13a --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,66 @@ +#!/bin/sh +# pre-commit hook:验证多语言源文件,检测手动修改生成文件 +# 模型 B:生成文件不入库(由 CI 自动生成并提交),提交时忽略它们 +set -e + +if [ -z "$(git diff --cached --name-only -- "script/multilingual-docs/")" ]; then + exit 0 +fi + +# 优先使用 venv 的 python +PYTHON="python" +if [ -f ".venv/Scripts/python" ]; then + PYTHON=".venv/Scripts/python" +elif [ -f ".venv/bin/python" ]; then + PYTHON=".venv/bin/python" +fi + +echo "📋 检测到多语言源文件变更..." +$PYTHON script/manage_templates.py --check + +# ── 生成到临时目录(期望结果),与工作区比对:收集不一致的生成文件 ── +GEN_TMP="$(mktemp -d)" +trap 'rm -rf "$GEN_TMP" 2>/dev/null || true' EXIT +$PYTHON script/manage_templates.py script/multilingual-docs/ "$GEN_TMP/.github/ISSUE_TEMPLATE/" --doc-dir "$GEN_TMP" >/dev/null + +mismatched="" +for gen in $(find "$GEN_TMP" -type f); do + rel="${gen#"$GEN_TMP"/}" + if [ -f "$rel" ] && ! diff -q "$gen" "$rel" >/dev/null 2>&1; then + mismatched="$mismatched $rel" + fi +done + +if [ -n "$mismatched" ]; then + echo -e "\n 以下生成文件与源文件不一致(可能被手动修改或未重新生成):" + for rel in $mismatched; do + echo " - $rel" + done + echo "" + echo " 请通过源文件修改 script/multilingual-docs/ 下的 YAML,不要直接编辑生成文件;" + echo " 也可以选择重新生成到工作区,预览最新效果。" + echo -n " 是否重新生成并继续提交?[y/N] " + answer="" + # GIT_HOOK_NONINTERACTIVE:测试/CI 等非交互环境跳过询问,默认视为 N + if [ -z "${GIT_HOOK_NONINTERACTIVE:-}" ]; then + if [ -t 0 ]; then + read -r answer || true + else + # 钩子 stdin 默认是 /dev/null,交互提交时改从终端读取 + read -r answer < /dev/tty || true + fi + fi + case "$answer" in + [Yy]*) + echo " 正在重新生成到工作区..." + $PYTHON script/manage_templates.py + ;; + *) + echo " 已取消提交。" + exit 1 + ;; + esac +else + # 无不一致:生成到工作区(本地方便预览);生成文件不入库,由 CI 自动生成提交 + $PYTHON script/manage_templates.py +fi diff --git "a/.github/ISSUE_TEMPLATE/bug-\346\217\220\344\272\244-\347\256\200\344\275\223\344\270\255\346\226\207-.yml" "b/.github/ISSUE_TEMPLATE/bug-\346\217\220\344\272\244-\347\256\200\344\275\223\344\270\255\346\226\207-.yml" deleted file mode 100644 index 9d989a36e..000000000 --- "a/.github/ISSUE_TEMPLATE/bug-\346\217\220\344\272\244-\347\256\200\344\275\223\344\270\255\346\226\207-.yml" +++ /dev/null @@ -1,100 +0,0 @@ -name: Bug 提交(简体中文) -description: 提交 BUG -labels: bug - -body: -- type: markdown - attributes: - value: "### 欢迎!" -- type: markdown - attributes: - value: | - 感谢您提交议题!请补充以下内容,以便我们能更好地协助您。 - 提交议题前确保您已阅读[常见问题(FAQ)](https://github.com/maboloshi/github-chinese/issues/493)。 -- type: textarea - id: description - attributes: - label: 问题/建议 - description: 请描述你遇到的问题/提出的建议。 - validations: - required: true -- type: textarea - id: steps - attributes: - label: 步骤 - description: 请逐步描述你遇到的问题,并带上测试链接(如有)。 - validations: - required: true -- type: textarea - id: expectation - attributes: - label: 预期 - description: 请描述你对本插件行为的预期。 - validations: - required: true -- type: textarea - id: realization - attributes: - label: 实际 - description: 请描述本插件的实际行为。 - validations: - required: true -- type: textarea - id: evidence - attributes: - label: 附件 - description: 请提供相关截图或附件(如有)。 - validations: - required: false -- type: dropdown - id: browser-name - attributes: - label: 浏览器名称 - description: 请选择运行本插件的浏览器的名称。 - options: - - Microsoft Edge - - Google Chrome - - Others - validations: - required: true -- type: input - id: browser-version - attributes: - label: 浏览器版本 - description: | - 请填入运行本插件的浏览器的版本。 - [Microsoft Edge 版本](https://support.microsoft.com/zh-cn/microsoft-edge/c726bee8-c42e-e472-e954-4cf5123497eb) - [Google Chrome 版本](chrome://settings/help) - placeholder: 版本 146.0.3856.62 (正式版本) (arm64) - validations: - required: true -- type: dropdown - id: script-manager-name - attributes: - label: 脚本管理器名称 - description: 请选择管理本插件的脚本管理器的名称。 - options: - - 篡改猴(Tampermonkey) - - Others - validations: - required: true -- type: input - id: script-manager-version - attributes: - label: 脚本管理器版本 - description: | - 请填入管理本插件的脚本管理器的版本。 - [Microsoft Edge 扩展](https://support.microsoft.com/zh-cn/topic/a3ae1ebb-8e7f-49df-a5f8-8c3f56c8078b) - placeholder: "5.4.1" - validations: - required: true -- type: input - id: plugin-version - attributes: - label: 插件版本 - description: | - 请填入 GitHub 中文化插件的版本。 - 见 [GitHub 中文化插件](extension://iikmkjmpaadaobahmlepeloendndfphd/options.html#nav=49f369f3-16e7-423f-86d9-1aa23aa2fd1c)源码中 `@version` 的值(不再接受 1.9.2 版本反馈)。 - placeholder: "1.9.3" - validations: - required: true diff --git "a/.github/ISSUE_TEMPLATE/bug-\346\217\220\344\272\244-\347\271\201\351\253\224\344\270\255\346\226\207-.yml" "b/.github/ISSUE_TEMPLATE/bug-\346\217\220\344\272\244-\347\271\201\351\253\224\344\270\255\346\226\207-.yml" deleted file mode 100644 index 8353dca3c..000000000 --- "a/.github/ISSUE_TEMPLATE/bug-\346\217\220\344\272\244-\347\271\201\351\253\224\344\270\255\346\226\207-.yml" +++ /dev/null @@ -1,100 +0,0 @@ -name: Bug 提交(繁體中文) -description: 提交 BUG -labels: bug - -body: -- type: markdown - attributes: - value: "### 欢迎!" -- type: markdown - attributes: - value: | - 感謝您提交議題!請補充以下內容,以便我們能更好地協助您: - 提交議題前確保您已閲讀[常見問題(FAQ)](https://github.com/maboloshi/github-chinese/issues/493)。 -- type: textarea - id: description - attributes: - label: 問題/建議 - description: 請描述你遇到的問題/提出的建議。 - validations: - required: true -- type: textarea - id: steps - attributes: - label: 步骤 - description: 請逐步描述你遇到的問題,并帶上測試連結(如有)。 - validations: - required: true -- type: textarea - id: expectation - attributes: - label: 預期 - description: 請描述你对本插件行為的預期。 - validations: - required: true -- type: textarea - id: realization - attributes: - label: 實際表現 - description: 請描述本插件的實際表現。 - validations: - required: true -- type: textarea - id: evidence - attributes: - label: 附件 - description: 請提供相关相關截圖或附件(如有)。 - validations: - required: false -- type: dropdown - id: browser-name - attributes: - label: 瀏覽器名稱 - description: 請選择運行本插件的瀏覽器的名稱。 - options: - - Microsoft Edge - - Google Chrome - - Others - validations: - required: true -- type: input - id: browser-version - attributes: - label: 瀏覽器版本 - description: | - 請填入運行本插件的瀏覽器的版本。 - [Microsoft Edge 版本](https://support.microsoft.com/zh-cn/microsoft-edge/c726bee8-c42e-e472-e954-4cf5123497eb) - [Google Chrome 版本](chrome://settings/help) - placeholder: 版本 146.0.3856.62 (正式版本) (arm64) - validations: - required: true -- type: dropdown - id: script-manager-name - attributes: - label: 腳本管理器名稱 - description: 請選择管理本插件的腳本管理器的名稱。 - options: - - 篡改猴(Tampermonkey) - - Others - validations: - required: true -- type: input - id: script-manager-version - attributes: - label: 腳本管理器版本 - description: | - 請填入管理本插件的腳本管理器的版本。 - [Microsoft Edge 扩展](https://support.microsoft.com/zh-cn/topic/a3ae1ebb-8e7f-49df-a5f8-8c3f56c8078b) - placeholder: 5.4.1 - validations: - required: true -- type: input - id: plugin-version - attributes: - label: 插件版本 - description: | - 請填入 GitHub 中文化插件的版本。 - 見 [GitHub 中文化插件](extension://iikmkjmpaadaobahmlepeloendndfphd/options.html#nav=49f369f3-16e7-423f-86d9-1aa23aa2fd1c)源码中 `@version` 的值(不再接受 1.9.2 版本反饋)。 - placeholder: 1.9.3 - validations: - required: true diff --git a/.github/workflows/check_issue_template_consistency.yml b/.github/workflows/check_issue_template_consistency.yml new file mode 100644 index 000000000..684442fb3 --- /dev/null +++ b/.github/workflows/check_issue_template_consistency.yml @@ -0,0 +1,63 @@ +name: 多语言文件一致性 +on: + pull_request: + paths: + - 'script/multilingual-docs/**' + - 'script/manage_templates.py' + - 'pyproject.toml' + - '.githooks/**' + - 'test/test_pre_commit_hook.sh' + push: + paths: + - 'script/multilingual-docs/**' + - 'script/manage_templates.py' + - 'pyproject.toml' + - '.githooks/**' + - 'test/test_pre_commit_hook.sh' + workflow_dispatch: + +permissions: + contents: write + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + python script/manage_templates.py --requirements + pip install -r script/requirements.txt + + # ── PR:验证 + 试生成(不提交) ── + - name: Validate & dry-run + if: github.event_name == 'pull_request' + run: | + python script/manage_templates.py --check + python script/manage_templates.py + + # ── PR:测试 pre-commit 钩子行为 ── + - name: Test pre-commit hook + if: github.event_name == 'pull_request' + run: bash test/test_pre_commit_hook.sh + + # ── 默认分支:验证 + 生成 + 自动提交(分支名语义化,随默认分支自适应) ── + - name: Generate & commit + if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) + run: | + python script/manage_templates.py + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + # 生成文件已 gitignore,需 -f 强制加回 + git add -f .github/ISSUE_TEMPLATE/ CONTRIBUTING.md CONTRIBUTING_zh-TW.md README.md README_zh-TW.md vscode-extension/README.md vscode-extension/README_zh-TW.md + if git diff --cached --exit-code; then + echo "No changes." + else + git commit -m "chore: auto-generate multilingual files" + git push + fi diff --git a/.github/workflows/update_contributors_images.yml b/.github/workflows/update_contributors_images.yml index cab899deb..89690b0b7 100644 --- a/.github/workflows/update_contributors_images.yml +++ b/.github/workflows/update_contributors_images.yml @@ -27,17 +27,21 @@ jobs: filter-author: (action-assistant\[bot\]|renovate\[bot\]|renovate-bot|@github-actions-bot|dependabot\[bot\]|ImgBotApp|imgbot\[bot\]) avatarSize: 42 - - name: Modify README.md + - name: Setup Python and install dependencies + uses: actions/setup-python@v5 + with: + python-version: '3.12' + - run: pip install -r script/requirements.txt + + - name: Update README.yml contributors and regenerate docs env: HTML_LIST: ${{ steps.contributors.outputs.htmlList }} run: | - escapedHtmlList=$(echo -e "$HTML_LIST" | sed ':a;N;$!ba;s/\n/\\n/g;s/\\n$//') - openDelimiter='' - closeDelimiter='' - sed -i "/$openDelimiter/,/$closeDelimiter/c\\$openDelimiter$escapedHtmlList$closeDelimiter" README.md - git diff --quiet --exit-code README.md || echo "CHANGES_DETECTED=true" >> $GITHUB_ENV + printf '%s' "$HTML_LIST" | python script/update_contributors.py + python script/manage_templates.py + git diff --quiet --exit-code README.md README_zh-TW.md script/multilingual-docs/README.yml || echo "CHANGES_DETECTED=true" >> $GITHUB_ENV - - name: Commit and push README.md + - name: Commit and push docs if: ${{ env.CHANGES_DETECTED == 'true' }} env: GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} @@ -47,5 +51,5 @@ jobs: -R "${{ github.repository }}" \ -B "${{ github.ref_name }}" \ -P "${{ github.sha }}" \ - -F "README.md" \ + -F "README.md README_zh-TW.md script/multilingual-docs/README.yml" \ -h "修改文档: 更新\`贡献者列表\`" diff --git a/.gitignore b/.gitignore index f717e0652..76943bb36 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,15 @@ Desktop.ini main(local).js # VS Code extension package *.vsix + +# Python +.venv/ + +# 多语言生成文件(由 CI 自动生成并提交,不入库) +/CONTRIBUTING.md +/CONTRIBUTING_zh-TW.md +/README.md +/README_zh-TW.md +vscode-extension/README.md +vscode-extension/README_zh-TW.md +.github/ISSUE_TEMPLATE/bug-*.yml diff --git a/README.md b/README.md deleted file mode 100644 index 21e996e84..000000000 --- a/README.md +++ /dev/null @@ -1,447 +0,0 @@ -
- -# [GitHub 中文化插件][github-project-link] - -> 让 GitHub 界面全面中文化 | 源自 [52cik/github-hans](https://github.com/52cik/github-hans) - -**简体中文** · [繁體中文](./README_zh-TW.md) · [反馈问题][github-issues-link] - - - -[![GitHub stars][github-stars-shield]][github-stars-link] -[![GitHub forks][github-forks-shield]][github-forks-link] -[![GitHub issues][github-issues-shield]][github-issues-link] -[![license GPL-3.0][github-license-shield]][github-license-link] -[![GreasyFork installs][greasyFork-shield]][greasyFork-link] - - - - - - Featured|HelloGitHub - - - -
- -> [!warning] -> 本项目从未发布至 GitCode,如您发现请截图并保留证据 - -
-目录树 - -#### TOC -- [🌟 功能特性](#-功能特性) -- [🌐 兼容环境](#-兼容环境) -- [💻 安装指南](#-安装指南) - - [浏览器(Tampermonkey)](#浏览器tampermonkey) - - [VS Code 市场扩展](#vs-code-市场扩展) -- [🔧 本地调试](#-本地调试) -- [🔄 更新日志](#-更新日志) -- [📌 待办事项](#-待办事项) -- [🤝 参与贡献](#-参与贡献) -- [🖼️ 效果预览](#-效果预览) -- [🙏 特别鸣谢](#-特别鸣谢) -- [📈 项目统计](#-项目统计) -- [🎁 欢迎打赏](#-欢迎打赏) -
- -## 🌟 功能特性 - -- [x] 全面中文化 GitHub 界面元素(菜单栏、标题、按钮等) -- [x] 智能正则匹配功能 -- [x] 支持项目描述的人机翻译 -- [x] 自动本地化时间元素 -- [x] 持续更新词库 - -## 🌐 兼容环境 - -浏览器类型 | 支持的脚本管理器 -:------------------: | :---------------: -Chrome / Chromium 内核 | [Tampermonkey][Tampermonkey], [Violentmonkey][Violentmonkey] -Safari(全平台) | [Tampermonkey][Tampermonkey], [Macaque][Macaque], [Stay][Stay] -Firefox / Gecko 内核 | [Tampermonkey][Tampermonkey], [Violentmonkey][Violentmonkey] -Via(Android) | 内置管理器 -VS Code 集成浏览器 | [Integrated Browser Extensions][Integrated Browser Extensions](扩展的源码仓库已删除) - -## 💻 安装指南 - -### 浏览器(Tampermonkey) - -1. 安装用户脚本管理器: - - 推荐:[Tampermonkey][Tampermonkey] -1. **基于 Chrome / Chromium 内核浏览器:** - 1. 务必开启 “扩展程序” 管理中的 **“开发者模式”**[^1] - 1. 务必开启 “扩展程序” 管理中脚本管理器扩展的 **“允许运行用户脚本”** - 1. 具体可参考 [Tampermonkey 官方指引](https://www.tampermonkey.net/faq.php#Q209) -1. 选择安装源: - - [GitHub 源【开发版】][main.user.js] - - [南大镜像源【开发版】][main(nju.edu).user.js] - - [GreasyFork 源【稳定版】][main(greasyfork).user.js] -1. 刷新页面后,插件即可生效 -1. 必要时,重启浏览器 - -[^1]: [Chrome 切换到 Manifest V3后,使用问题](https://github.com/maboloshi/github-chinese/issues/234) - -> [!NOTE] -> **版本说明**: -> - 🚀 开发版:实时更新,每周五自动更新词库 -> - 🛡️ 稳定版:每周一同步开发版词库,更稳定 - -### VS Code 集成浏览器(Integrated Browser Extensions) - -请参考[扩展的自述文件](vscode-extension/README.md)。 - -## 🔧 本地调试 - -1. 安装 [Tampermonkey][Tampermonkey],并启用 “允许访问文件网址”。 -1. 下载词库文件到本地(如:`D:\github-chinese\locals.js`) -1. 在脚本管理器中修改引用路径: - ```js - // 原始路径 - // @require https://raw.githubusercontent.com/... - - // 修改为 - // @require file:///D:/github-chinese/locals.js - ``` -1. 刷新页面生效 - -> [!IMPORTANT] -> **若无效:** -> 1. 进入 [Tampermonkey][Tampermonkey] 插件`设置页` -> 1. 将 `通用 - 配置模式` 设置为`高级`,进入高级设置模式 -> 1. 找到 `安全 - 允许脚本访问本地文件` 并设置为 `外部(@require 和 @resource)` - -> [!TIP] -> 💡 **温馨提示:** 您可以将词库文件拖拽至浏览器地址栏,复制路径直接使用。 - -
- -[![][back-to-top]](#readme-top) - -
- - -## 🔄 更新日志 - -### 最新版本 - -#### v1.9.4.4 (2026-06-20) - -1. 兼容修复`1.9.2.4`,`1.9.4.4`: - - 区分 React GlobalNav 与页面主体共享的 Primer 弹层,恢复下拉菜单即时、完整翻译。 - -#### v1.9.4.3 (2026-06-17) - -1. 兼容修复`1.9.2.3`,`1.9.4.3`: - - 收窄 React 搜索模块忽略范围,恢复仓库议题页和搜索页主体区域翻译。 - -#### v1.9.4.2 (2026-06-17) - -1. 兼容修复`1.9.2.2`,`1.9.4.2`: - - 在保持 React 头部搜索框稳定的前提下,恢复头部导航、菜单、搜索弹层和提示翻译。 - -#### v1.9.4.1 (2026-06-16) - -1. 临时修复`1.9.2`,`1.9.4`: - - 关于 GitHub 引入 React 机制导致头部搜索框消失。副作用整个头部导航全部加入忽略规则,无法翻译。 - -#### v1.9.4 (2026-05-17) - -1. 代码重构: - - 全面结构化重组:抽离配置常量 `CONFIG`、状态管理器 `State` - - 引入 `safe()` 错误边界包裹关键函数,便于排错 - - 函数拆分细化:`watchUpdate` → `setupMutationObserver` + `processMutations`,`transDesc` → `handleTransClick` + `requestRemoteTrans` + `showTransResult` - - `processMutations` 祖先去重:同一批 mutation 中后代节点不再重复遍历 -1. 新增功能: - - 翻译结果 UI 暗色主题适配(CSS 变量 + `prefers-color-scheme` 媒体查询),使用 `GM_addStyle` 插入 - - 未命中词条管理器 `MissedTermsManager`(记录、导出 JSON、清空、统计、菜单) - - 开发者模式(`CONFIG.DEV`)控制未命中词条菜单显隐 - - Tampermonkey `onurlchange` 事件支持(`setupUrlChangeListener`) -1. 修复: - - 修复翻译 API 响应 XSS 漏洞:`innerHTML` 模板拼接改为 `textContent` 安全赋值(由 #692 报告) - - 修复 TreeWalker 过滤器在 `ignoreSelectors` 为空时抛出 `SyntaxError` - - 修复翻译按钮可能重复添加的问题(`nextSibling` 空值检查) - - 修复 `RELATIVE-TIME` shadowRoot 为 null 时的崩溃 - - 修复从未识别页面离开后 `State.pageConfig` 未清空,导致旧配置残留的问题 -1. 性能优化:减少无效迭代,消除不必要的 DOM 遍历 - -#### v1.9.3 (2024-08-18) - -1. 新增功能:通过设置中文环境,自动本地化时间元素,仅保留`on`开头的时间正则,并停用时间元素监视 -1. 优化突变翻译处理: - - 引入`characterDataPage`规则,对特定页面启用`筛选字符数据`的变更 - - 引入`ignoreMutationSelectorPage`规则,忽略特定突变元素 -1. 合并`reIgnoreClass,reIgnoreItemprop,ignoreId,ignoreTag`为`ignoreSelectorPage`规则,处理全局及特定页面,忽略特定元素 -1. 引入全局缓存模式,减少重复构建包括不限于基于`page`变化的忽略规则、正则规则数组等 -1. 调整:更新讯飞听见翻译引擎v2.0 -1. 优化:梳理、优化脚本 -1. 调整:调整词库语言代码为`zh-CN`, 与环境语言设置一致 - -
查看更多历史版本 - -#### v1.9.2 (2024-06-14) - -1. 适配`www.githubstatus.com` -1. 适配`skills.github.com` - -#### v1.9.1 (2024-05-23) - -1. 更新`切换正则功能按钮` - -#### v1.9.0 (2023-12-09) - -1. 重新定义版本号规则, 如`1.9.0-2023-12-09`。 - - `1.9.0`: 主版本号(由项目所有者更新) - - `2023-12-09`:`词库`发布版本号(由 GitHub Action 自动更新) -1. 加强: [GitHub 源【开发版】][main.user.js]每周一凌晨自动更新`词库`发布版本号 -1. 加强: [GreasyFork 源【稳定版】][main(greasyfork).user.js]每周五凌晨自动更新`词库`发布版本号, 词库内容同上一次[GitHub 源【开发版】][main.user.js] -1. 加强:在 `README.md` 中自动更新贡献者头像 -1. 更新: 忽略规则, 词条等 - -#### v1.8.5 (2023-08-31) - -1. 优化: `transDesc 函数`代码 -1. 修复: 重复添加`translate-me`翻译按钮 -1. 加强:`watchUpdate 函数`新增节点文本更新的情况 -1. 调整: `transBySelector和transDesc函数`延迟执行时间 -1. 更新: 忽略规则, 词条等 - -#### v1.8.4 (2023-08-08) - -1. 修复: `Itemprop`过滤规则, 依然使用正则方式 -1. 修复: `tooltipped`样式提示, 依然使用正则方式 - -#### v1.8.3 (2023-08-07) - -1. 梳理、优化脚本 -1. 更新: 忽略规则, 大量词条等 - -#### v1.8.2 (2023-05-15) - -1. `greasyfork 托管`源切换到`按页面精细化词条模式` -1. 调整词库格式 -1. 功能加强: 优化`元素筛选器`翻译逻辑 -1. 更新: 忽略规则, 大量词条等 - -#### v1.8.1 (2023-01-22) - -1. 修复: #8 与 dark reader 扩展发生冲突,导致时间显示出现问题 -1. `GitHub`源开始切换到`按页面精细化词条模式(开发版)`, 词库未完全迁移适配 -1. 停止`greasyfork`源词库文件的同步更新 - -#### v1.8.0 (2023-01-18) - -1. 删除: `TURBO-FRAME`框架处理代码. Github 已调整新动态加载模式, 直接检测`url`的变化就能获取对应的`page`信息 -1. 新增: 支持时间元素的`Shadow DOM`翻译, 并监听变化 -1. 新增: 启用并更新`时间元素翻译`专项正则词条 -1. 新增: 仅当`page`有效才翻译页面 -1. 修复: 原`简介翻译`引擎`GitHub中文社区`失效, 改为`讯飞`引擎(测试) -1. 修复: 追加公共正则重复迭代的问题 -1. 修复: 正则标记变量`RegExp`与构造函数`new RegExp`冲突 -1. 更新: 忽略规则, 词条等 - -预告, 下次将细化`page`匹配规则, 导致词库文件结构大调整, 词库文件会适当变大, 页面正则更精细效率会提升 - -#### v1.7.9 (2022-07-17) - -GitHub 的 ajax 载入方式逐步从 [defunkt/jquery-pjax](https://github.com/defunkt/jquery-pjax) 切换到 [hotwired/turbo](turbo.hotwired.dev), 导致已有的动态监测方式逐步失效 - -目前, 通过以下修复: - -1. 新增 `BODY` 元素新增监视 -1. 解析 `TURBO-FRAME` 框架, 获取对应的 `page` -1. 修复 github 新动态加载模式, 导致`翻译描述`返回值无法插入 -1. 修复 github 新动态加载模式, 导致`chrome`浏览器自带翻译功能卡死页面 - -其他更新: - -1. 修复`rePagePath`,`rePagePathRepo`,`rePagePathOrg`匹配规则,限制路径匹配层次,排除干扰 -1. 直接使用网页URL`document.URL`变化触发`标题翻译`和`JS 筛选器`翻译 -1. 修复`关闭正则`无法生效, 需要刷新页面才生效 -1. 日常更新词库和忽略规则 -1. 更新`JS 筛选器`规则 - -#### v1.7.8 (2022-06-29) - -1. 紧急修复: GitHub 变更了`document.body`和`title`更新机制, 导致原有的`监测更新`规则部分失效, 目前使用`document.documentElement`监视整个页面 DOM 的变更 -1. 跳过``标签 -1. `标题翻译`和`JS 筛选器`翻译, 依据 URL变化更新 - -#### v1.7.7 (2022-06-26) - -1. 新增`时间元素翻译`功能 -1. 重写`页面标题翻译`函数 -1. 梳理`遍历节点`函数逻辑 -1. 优化`transPage`函数,默认翻译公共部分 -1. 调整`getPage`函数, 使`ClassName匹配规则`优先 -1. 优化`translate`函数, 跳过`不存在英文字母和符号,.`, 保留首尾空白部分等 -1. 部分函数重命名,使用`es6`新语法 -1. 日常更新词库和忽略规则,修复一个`JS 选择器规则` - -#### v1.7.6 (2022-05-12) - -1. 日常更新词库和忽略规则 -1. 添加手动开启/禁用正则翻译,添加切换菜单 -1. 优化翻译文本函数:避免已翻译词汇二次匹配,提高效率;局部翻译优先于全局 - -
- -
- -[![][back-to-top]](#readme-top) - -
- - -## 📌 待办事项 - -1. 添加 GitHub 专用名词解释 -1. 整理 [Git](https://git-scm.com/) & [GitHub](https://github.com/) 学习资料 -1. 完善文档翻译,需大家 PR 共同翻译 - -## 🤝 参与贡献 - -欢迎通过以下方式参与贡献: - -1. 完善词库翻译(编辑 `locals.js`) -1. 提交议题报告,参与话题讨论 -1. 改进代码逻辑 - -[![][pr-welcome-shield]][pr-welcome-link] - -### 翻译参考资源: - -1. [Pro Git 第二版 简体中文](https://git-scm.com/book/zh/v2) -1. [Pro Git: 翻译约定](https://github.com/progit/progit2-zh/blob/master/TRANSLATION_NOTES.asc) -1. [Git 官方软件包的简体中文翻译](https://github.com/git/git/blob/master/po/zh_CN.po) -1. [GitHub 词汇表官方译本](https://docs.github.com/cn/get-started/quickstart/github-glossary) -1. **[CSS 选择器](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Reference/Selectors) 用于编写忽略规则** - -> [查看详细贡献指南](https://github.com/maboloshi/github-chinese/discussions/57) - -## 🖼️ 效果预览 - - - - - - - - - - - - -## 🙏 特别鸣谢 - -### 核心团队 - -- [maboloshi](https://github.com/maboloshi) - 项目作者 -- [wyc-26](https://github.com/wyc-26),[陈生杂物房](https://github.com/TC999) - 项目协作者 -- [52cik](https://github.com/52cik) - 项目原作者 - -### 贡献者墙 - -一如既往,感谢我们出色的贡献者❤️! - - -沙漠之子 -楼教主 -陈生杂物房 -wyc-26 -其智乃反不能及 -Lu Yifei -Paper Moon -cat-kun -大叶子 -Mr.Baoboer -Kise Platinyl -Pecasha -poney -人民的勤务员 -Sebastion -PtJade Ceramic -Oliver Lin -AlanWang -苓𥤚 -益生君 -小莫 -学渣驹 -叹号大帝 -前端小武 -wang4yu6peng13 -pangshitong -dayday -create new ██████╗  ██╔══██╗ ██████╔╝ ██╔══██╗ ██████╔╝ ╚═════╝    ██╗    ██╗   ██║    ██║   ██║    ██║   ██║    ██║   ╚█████╔╝    ╚═════╝  ███████╗ ██╔════╝  ██║████═╗  ██║    ██ ║ ╚██████╔╝   ╚══════╝ -Shuwn Hsu -NyA!K0 -MaydayV -KS-OTO -InfinityLoop -Imgbot -Heavenless -Flint Scophire -neveler - - -> 贡献者列表,由 [GitHub Action][update-contributors-images] 自动生成 - -
- -[![][back-to-top]](#readme-top) - -
- - -## 📈 项目统计 - - - - - - Star History Chart - - - -![Alt](https://repobeats.axiom.co/api/embed/ae4c378f0e6ec317654ec5c4e8b01218c734cd53.svg "Repobeats analytics image") - -
- -[![][back-to-top]](#readme-top) - -
- -## 🎁 欢迎打赏 -[赞赏列表](https://github.com/maboloshi/maboloshi/issues/1) -| 微信赞赏 | 支付宝赞赏 | -| :--------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------: | -| WeChat QRcode
☕喝点咖啡继续干☕ | AliPay QRcode
🌶️来包辣条吧~🍪 | - - - - -[back-to-top]: https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square -[github-project-link]: https://github.com/maboloshi/github-chinese "GitHub 中文化插件" -[github-issues-link]: https://github.com/maboloshi/github-chinese/issues "议题" -[github-issues-shield]: https://img.shields.io/github/issues/maboloshi/github-chinese?style=flat-square&logo=github&label=Issue -[github-stars-link]: https://github.com/maboloshi/github-chinese/stargazers "星标" -[github-stars-shield]: https://img.shields.io/github/stars/maboloshi/github-chinese?style=flat-square&logo=github&label=Star -[github-forks-link]: https://github.com/maboloshi/github-chinese/network "复刻" -[github-forks-shield]: https://img.shields.io/github/forks/maboloshi/github-chinese?style=flat-square&logo=github&label=Fork -[github-license-link]: https://opensource.org/licenses/GPL-3.0 "许可证" -[github-license-shield]: https://img.shields.io/github/license/maboloshi/github-chinese?style=flat-square&logo=github&label=License -[greasyFork-link]: https://greasyfork.org/scripts/435208 "GreasyFork 源 - GitHub 中文化插件" -[greasyFork-shield]: https://img.shields.io/greasyfork/dt/435208?style=flat-square&logo=GreasyFork&label=GreasyFork%20Installs -[pr-welcome-link]: https://github.com/maboloshi/github-chinese/pulls -[pr-welcome-shield]: https://img.shields.io/badge/🤯_pr_welcome-%E2%86%92-ffcb47?labelColor=black&style=for-the-badge "欢迎提交 PR" -[Tampermonkey]: http://tampermonkey.net/ "篡改猴" -[Violentmonkey]: https://violentmonkey.github.io/ "暴力猴" -[Macaque]: https://macaque.app/ "猕猴" -[Stay]: https://apps.apple.com/cn/app/stay-for-safari-%E6%B5%8F%E8%A7%88%E5%99%A8%E4%BC%B4%E4%BE%A3/id1591620171 "Stay" -[main.user.js]: https://github.com/maboloshi/github-chinese/raw/gh-pages/main.user.js "GitHub 中文化插件 - GitHub 源" -[main(nju.edu).user.js]:https://mirror.nju.edu.cn/github-chinese/main(nju.edu).user.js "GitHub 中文化插件 - 南大镜像源" -[main(greasyfork).user.js]: https://greasyfork.org/scripts/435208-github-%E4%B8%AD%E6%96%87%E5%8C%96%E6%8F%92%E4%BB%B6/code/GitHub%20%E4%B8%AD%E6%96%87%E5%8C%96%E6%8F%92%E4%BB%B6.user.js "GitHub 中文化插件 - GreasyFork 源" -[update-contributors-images]: https://github.com/maboloshi/github-chinese/blob/gh-pages/.github/workflows/update_contributors_images.yml -[Integrated Browser Extensions]: https://marketplace.visualstudio.com/items?itemName=boylett.integrated-browser-extensions "Integrated Browser Extensions" - diff --git a/README_zh-TW.md b/README_zh-TW.md deleted file mode 100644 index 046d980cb..000000000 --- a/README_zh-TW.md +++ /dev/null @@ -1,425 +0,0 @@ -
- -# [GitHub 中文化插件][github-project-link] - -> 讓 GitHub 界面全面中文化 | 源自 [52cik/github-hans](https://github.com/52cik/github-hans) - -[简体中文](./README.md) · **繁體中文** · [反饋問題][github-issues-link] - - - -[![GitHub issues][github-issues-shield]][github-issues-link] -[![GitHub stars][github-stars-shield]][github-stars-link] -[![GitHub forks][github-forks-shield]][github-forks-link] -[![license GPL-3.0][github-license-shield]][github-license-link] -[![GreasyFork installs][greasyFork-shield]][greasyFork-link] - - - - - - Featured|HelloGitHub - - - -
- -> [!warning] -> 本項目從未發佈至 GitCode,如您發現請截圖並保留證據 - -> [!IMPORTANT] -> 💡 **重要:** 本繁體語言版本,使用基於[OpenCC](https://github.com/BYVoid/OpenCC)及[自定義規則](./t2s_rules.conf)轉換 - -
-目錄樹 - -#### TOC -- [🌟 功能特性](#-功能特性) -- [🌐 兼容環境](#-兼容環境) -- [💻 安裝指南](#-安裝指南) -- [🔧 本地調試](#-本地調試) -- [🔄 更新日誌](#-更新日誌) -- [📌 待辦事項](#-待辦事項) -- [🤝 參與貢獻](#-參與貢獻) -- [🖼️ 效果預覽](#-效果預覽) -- [🙏 特別鳴謝](#-特別鳴謝) -- [📈 項目統計](#-項目統計) -- [🎁 歡迎打賞](#-歡迎打賞) -
- -## 🌟 功能特性 - -- [x] 全面中文化 GitHub 界面元素(菜單欄、標題、按鈕等) -- [x] 智能正則匹配功能 -- [x] 支持項目描述的人機翻譯 -- [x] 自動本地化時間元素 -- [x] 持續更新詞庫 - -## 🌐 兼容環境 - -瀏覽器類型 | 支持的腳本管理器 -:------------------: | :---------------: -Chrome / Chromium 內核 | [Tampermonkey][Tampermonkey], [Violentmonkey][Violentmonkey] -Safari(全平臺) | [Macaque][Macaque], [Stay][Stay] -Firefox / Gecko 內核 | [Tampermonkey][Tampermonkey], [Violentmonkey][Violentmonkey] -Via(Android) | 內置管理器 - -## 💻 安裝指南 - -1. 安裝用戶腳本管理器: - - 推薦:[Tampermonkey][Tampermonkey] -1. **基於 Chrome / Chromium 內核瀏覽器:** - 1. 務必開啟 「擴展程序」 管理中的 **「開發者模式」**[^1] - 1. 務必開啟 「擴展程序」 管理中腳本管理器擴展的 **「允許運行用戶腳本」** - 1. 具體可參考 [Tampermonkey 官方指引](https://www.tampermonkey.net/faq.php#Q209) -1. 選擇安裝源: - - [GitHub 源【開發版】][main_zh-TW.user.js] -1. 刷新頁面後,插件即可生效 -1. 必要時,重啟瀏覽器 - -[^1]: [Chrome 切換到 Manifest V3後,使用問題](https://github.com/maboloshi/github-chinese/issues/234) - -> [!NOTE] -> **版本說明**: -> - 🚀 開發版:實時更新,每週五自動更新詞庫 -> - 🛡️ 穩定版:每週一同步開發版詞庫,更穩定 - -## 🔧 本地調試 - -1. 安裝 [Tampermonkey][Tampermonkey],並啟用 “允許訪問文件網址”。 -1. 下載詞庫文件到本地(如:`D:\github-chinese\locals.js`) -1. 在腳本管理器中修改引用路徑: - ```js - // 原始路徑 - // @require https://raw.githubusercontent.com/... - - // 修改為 - // @require file:///D:/github-chinese/locals.js - ``` -1. 刷新頁面生效 - -> [!TIP] -> 💡 **溫馨提示:** 您可以將詞庫文件拖拽至瀏覽器地址欄,複製路徑直接使用。 - -
- -[![][back-to-top]](#readme-top) - -
- - -## 🔄 更新日誌 - -### 最新版本 - -#### v1.9.4.4 (2026-06-20) - -1. 相容修復`1.9.2.4`,`1.9.4.4`: - - 區分 React GlobalNav 與頁面主體共用的 Primer 彈層,恢復下拉選單即時、完整翻譯。 - -#### v1.9.4.3 (2026-06-17) - -1. 相容修復`1.9.2.3`,`1.9.4.3`: - - 收窄 React 搜尋模組忽略範圍,恢復倉庫議題頁和搜尋頁主體區域翻譯。 - -#### v1.9.3 (2024-08-18) - -1. 新增功能:通過設置中文環境,自動本地化時間元素,僅保留`on`開頭的時間正則,並停用時間元素監視 -1. 優化突變翻譯處理: - - 引入`characterDataPage`規則,對特定頁面啟用`篩選字符數據`的變更 - - 引入`ignoreMutationSelectorPage`規則,忽略特定突變元素 -1. 合併`reIgnoreClass,reIgnoreItemprop,ignoreId,ignoreTag`為`ignoreSelectorPage`規則,處理全局及特定頁面,忽略特定元素 -1. 引入全局緩存模式,減少重複構建包括不限於基於`page`變化的忽略規則、正則規則數組等 -1. 調整:更新訊飛聽見翻譯引擎v2.0 -1. 優化:梳理、優化腳本 -1. 調整:調整詞庫語言代碼為`zh-CN`, 與環境語言設置一致 - -
查看更多歷史版本 - -#### v1.9.2 (2024-06-14) - -1. 適配`www.githubstatus.com` -1. 適配`skills.github.com` - -#### v1.9.1 (2024-05-23) - -1. 更新`切換正則功能按鈕` - -#### v1.9.0 (2023-12-09) - -1. 重新定義版本號規則, 如`1.9.0-2023-12-09`。 - - `1.9.0`: 主版本號(由項目所有者更新) - - `2023-12-09`:`詞庫`發佈版本號(由 GitHub Action 自動更新) -1. 加強: [GitHub 源【開發版】][main.user.js]每週一凌晨自動更新`詞庫`發佈版本號 -1. 加強: [GreasyFork 源【穩定版】][main(greasyfork).user.js]每週五凌晨自動更新`詞庫`發佈版本號, 詞庫內容同上一次[GitHub 源【開發版】][main.user.js] -1. 加強:在 `README.md` 中自動更新貢獻者頭像 -1. 更新: 忽略規則, 詞條等 - -#### v1.8.5 (2023-08-31) - -1. 優化: `transDesc 函數`代碼 -1. 修復: 重複添加`translate-me`翻譯按鈕 -1. 加強:`watchUpdate 函數`新增節點文本更新的情況 -1. 調整: `transBySelector和transDesc函數`延遲執行時間 -1. 更新: 忽略規則, 詞條等 - -#### v1.8.4 (2023-08-08) - -1. 修復: `Itemprop`過濾規則, 依然使用正則方式 -1. 修復: `tooltipped`樣式提示, 依然使用正則方式 - -#### v1.8.3 (2023-08-07) - -1. 梳理、優化腳本 -1. 更新: 忽略規則, 大量詞條等 - -#### v1.8.2 (2023-05-15) - -1. `greasyfork 託管`源切換到`按頁面精細化詞條模式` -1. 調整詞庫格式 -1. 功能加強: 優化`元素篩選器`翻譯邏輯 -1. 更新: 忽略規則, 大量詞條等 - -#### v1.8.1 (2023-01-22) - -1. 修復: #8 與 dark reader 擴展發生衝突,導致時間顯示出現問題 -1. `GitHub`源開始切換到`按頁面精細化詞條模式(開發版)`, 詞庫未完全遷移適配 -1. 停止`greasyfork`源詞庫文件的同步更新 - -#### v1.8.0 (2023-01-18) - -1. 刪除: `TURBO-FRAME`框架處理代碼. Github 已調整新動態加載模式, 直接檢測`url`的變化就能獲取對應的`page`信息 -1. 新增: 支持時間元素的`Shadow DOM`翻譯, 並監聽變化 -1. 新增: 啟用並更新`時間元素翻譯`專項正則詞條 -1. 新增: 僅當`page`有效才翻譯頁面 -1. 修復: 原`簡介翻譯`引擎`GitHub中文社區`失效, 改為`訊飛`引擎(測試) -1. 修復: 追加公共正則重複迭代的問題 -1. 修復: 正則標記變量`RegExp`與構造函數`new RegExp`衝突 -1. 更新: 忽略規則, 詞條等 - -預告, 下次將細化`page`匹配規則, 導致詞庫文件結構大調整, 詞庫文件會適當變大, 頁面正則更精細效率會提升 - -#### v1.7.9 (2022-07-17) - -GitHub 的 ajax 載入方式逐步從 [defunkt/jquery-pjax](https://github.com/defunkt/jquery-pjax) 切換到 [hotwired/turbo](turbo.hotwired.dev), 導致已有的動態監測方式逐步失效 - -目前, 通過以下修復: - -1. 新增 `BODY` 元素新增監視 -1. 解析 `TURBO-FRAME` 框架, 獲取對應的 `page` -1. 修復 github 新動態加載模式, 導致`翻譯描述`返回值無法插入 -1. 修復 github 新動態加載模式, 導致`chrome`瀏覽器自帶翻譯功能卡死頁面 - -其他更新: - -1. 修復`rePagePath`,`rePagePathRepo`,`rePagePathOrg`匹配規則,限制路徑匹配層次,排除干擾 -1. 直接使用網頁URL`document.URL`變化觸發`標題翻譯`和`JS 篩選器`翻譯 -1. 修復`關閉正則`無法生效, 需要刷新頁面才生效 -1. 日常更新詞庫和忽略規則 -1. 更新`JS 篩選器`規則 - -#### v1.7.8 (2022-06-29) - -1. 緊急修復: GitHub 變更了`document.body`和`title`更新機制, 導致原有的`監測更新`規則部分失效, 目前使用`document.documentElement`監視整個頁面 DOM 的變更 -1. 跳過``標籤 -1. `標題翻譯`和`JS 篩選器`翻譯, 依據 URL變化更新 - -#### v1.7.7 (2022-06-26) - -1. 新增`時間元素翻譯`功能 -1. 重寫`頁面標題翻譯`函數 -1. 梳理`遍歷節點`函數邏輯 -1. 優化`transPage`函數,默認翻譯公共部分 -1. 調整`getPage`函數, 使`ClassName匹配規則`優先 -1. 優化`translate`函數, 跳過`不存在英文字母和符號,.`, 保留首尾空白部分等 -1. 部分函數重命名,使用`es6`新語法 -1. 日常更新詞庫和忽略規則,修復一個`JS 選擇器規則` - -#### v1.7.6 (2022-05-12) - -1. 日常更新詞庫和忽略規則 -1. 添加手動開啟/禁用正則翻譯,添加切換菜單 -1. 優化翻譯文本函數:避免已翻譯詞彙二次匹配,提高效率;局部翻譯優先於全局 - -
- -
- -[![][back-to-top]](#readme-top) - -
- - -## 📌 待辦事項 - -1. 添加 GitHub 專用名詞解釋 -1. 整理 [Git](https://git-scm.com/) & [GitHub](https://github.com/) 學習資料 -1. 完善文檔翻譯,需大家 PR 共同翻譯 - -## 🤝 參與貢獻 - -歡迎通過以下方式參與貢獻: - -1. 完善詞庫翻譯(編輯 `locals.js`) -1. 提交議題報告,參與話題討論 -1. 改進代碼邏輯 - -[![][pr-welcome-shield]][pr-welcome-link] - -### 翻譯參考資源: - -1. [Pro Git 第二版 簡體中文](https://git-scm.com/book/zh/v2) -1. [Pro Git: 翻譯約定](https://github.com/progit/progit2-zh/blob/master/TRANSLATION_NOTES.asc) -1. [Git 官方軟件包的簡體中文翻譯](https://github.com/git/git/blob/master/po/zh_CN.po) -1. [GitHub 詞彙表官方譯本](https://docs.github.com/cn/get-started/quickstart/github-glossary) -1. **[CSS 選擇器](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Reference/Selectors) 用於編寫忽略規則** - -> [查看詳細貢獻指南](https://github.com/maboloshi/github-chinese/discussions/57) - -## 🖼️ 效果預覽 - - - - - - - - - - - - -## 🙏 特別鳴謝 - -### 核心團隊 - -- [maboloshi](https://github.com/maboloshi) - 項目作者 -- [wyc-26](https://github.com/wyc-26),[陳生雜物房](https://github.com/TC999) - 項目協作者 -- [52cik](https://github.com/52cik) - 項目原作者 - -### 貢獻者牆 - -一如既往,感謝我們出色的貢獻者❤️! - - - - 沙漠之子 - - - 樓教主 - - - 陳生雜物房 - - - 其智乃反不能及 - - - wyc-26 - - - 大葉子 - - - cat-kun - - - 人民的勤務員 - - - 菾凴 - - - 𠭞 - - - 益生君 - - - 小莫 - - - 前端小武 - - - wang4yu6peng13 - - - pangshitong - - - dayday - - - create new ██████╗  ██╔══██╗ ██████╔╝ ██╔══██╗ ██████╔╝ ╚═════╝    ██╗    ██╗   ██║    ██║   ██║    ██║   ██║    ██║   ╚█████╔╝    ╚═════╝  ███████╗ ██╔════╝  ██║████═╗  ██║    ██ ║ ╚██████╔╝   ╚══════╝ - - - KS-OTO - - - InfinityLoop - - - Imgbot - - - neveler - - - -> 貢獻者列表,由 [GitHub Action][update-contributors-images] 自動生成 - -
- -[![][back-to-top]](#readme-top) - -
- - -## 📈 項目統計 - - - - - - Star History Chart - - - -![Alt](https://repobeats.axiom.co/api/embed/ae4c378f0e6ec317654ec5c4e8b01218c734cd53.svg "Repobeats analytics image") - -
- -[![][back-to-top]](#readme-top) - -
- -## 🎁 歡迎打賞 -[讚賞列表](https://github.com/maboloshi/maboloshi/issues/1) -| 微信讚賞 | 支付寶讚賞 | -| :--------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------: | -| WeChat QRcode
☕喝點咖啡繼續幹☕ | AliPay QRcode
🌶️來包辣條吧~🍪 | - - - - -[back-to-top]: https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square -[github-project-link]: https://github.com/maboloshi/github-chinese "GitHub 中文化插件" -[github-issues-link]: https://github.com/maboloshi/github-chinese/issues "議題" -[github-issues-shield]: https://img.shields.io/github/issues/maboloshi/github-chinese?style=flat-square&logo=github&label=Issue -[github-stars-link]: https://github.com/maboloshi/github-chinese/stargazers "星標" -[github-stars-shield]: https://img.shields.io/github/stars/maboloshi/github-chinese?style=flat-square&logo=github&label=Star -[github-forks-link]: https://github.com/maboloshi/github-chinese/network "復刻" -[github-forks-shield]: https://img.shields.io/github/forks/maboloshi/github-chinese?style=flat-square&logo=github&label=Fork -[github-license-link]: https://opensource.org/licenses/GPL-3.0 "許可證" -[github-license-shield]: https://img.shields.io/github/license/maboloshi/github-chinese?style=flat-square&logo=github&label=License -[greasyFork-link]: https://greasyfork.org/scripts/435208 "GreasyFork 源 - GitHub 中文化插件" -[greasyFork-shield]: https://img.shields.io/badge/dynamic/json?style=flat-square&logo=GreasyFork&label=GreasyFork&query=total_installs&suffix=%20installs&url=https://greasyfork.org/scripts/435208.json -[pr-welcome-link]: https://github.com/maboloshi/github-chinese/pulls -[pr-welcome-shield]: https://img.shields.io/badge/🤯_pr_welcome-%E2%86%92-ffcb47?labelColor=black&style=for-the-badge "歡迎提交 PR" -[Tampermonkey]: http://tampermonkey.net/ "篡改猴" -[Violentmonkey]: https://violentmonkey.github.io/ "暴力猴" -[Macaque]: https://macaque.app/ "獼猴" -[Stay]: https://apps.apple.com/cn/app/stay-for-safari-%E6%B5%8F%E8%A7%88%E5%99%A8%E4%BC%B4%E4%BE%A3/id1591620171 "Stay" -[main_zh-TW.user.js]: https://github.com/maboloshi/github-chinese/raw/gh-pages/main_zh-TW.user.js "GitHub 中文化插件(繁體版) - GitHub 託管" -[update-contributors-images]: https://github.com/maboloshi/github-chinese/blob/gh-pages/.github/workflows/update_contributors_images.yml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..522bb954f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,9 @@ +[project] +name = "github-chinese-scripts" +description = "GitHub 中文化插件辅助脚本" +requires-python = ">=3.10" +dependencies = [ + "pyyaml>=6.0", + "opencc-python-reimplemented>=0.1.7", + "Jinja2>=3.1", +] diff --git a/script/.gitignore b/script/.gitignore new file mode 100644 index 000000000..b5e88f1c7 --- /dev/null +++ b/script/.gitignore @@ -0,0 +1,2 @@ +requirements.txt +__pycache__/ \ No newline at end of file diff --git a/script/manage.cmd b/script/manage.cmd new file mode 100644 index 000000000..246935024 --- /dev/null +++ b/script/manage.cmd @@ -0,0 +1,24 @@ +@echo off +setlocal EnableDelayedExpansion + +set "SCRIPT_DIR=%~dp0" +set "VENV_PYTHON=%SCRIPT_DIR%..\.venv\Scripts\python.exe" + +if exist "%VENV_PYTHON%" ( + "%VENV_PYTHON%" "%SCRIPT_DIR%manage_templates.py" %* +) else ( + where py >nul 2>nul + if not errorlevel 1 ( + py -3 "%SCRIPT_DIR%manage_templates.py" %* + ) else ( + where python >nul 2>nul + if not errorlevel 1 ( + python "%SCRIPT_DIR%manage_templates.py" %* + ) else ( + for /f "usebackq delims=" %%I in (`powershell -NoProfile -Command "$culture=[System.Globalization.CultureInfo]::CurrentUICulture.Name.ToLowerInvariant(); if($culture -match '^(zh-(hk|mo|tw)|zh-hant)'){ '找不到 Python。請先安裝 Python 3,並確保 py 或 python 在 PATH 中。' } else { '未找到 Python。请先安装 Python 3,并确保 py 或 python 在 PATH 中。' }"`) do echo %%I + exit /b 1 + ) + ) +) + +exit /b %ERRORLEVEL% diff --git a/script/manage.ps1 b/script/manage.ps1 new file mode 100644 index 000000000..7e7dc1ae2 --- /dev/null +++ b/script/manage.ps1 @@ -0,0 +1,46 @@ +# manage_templates.py 的 UTF-8 包装:修复 Windows 管道下输出乱码 +# 用法: +# PowerShell: .\script\manage.ps1 [--check | --requirements | ...] +# CMD: .\script\manage.cmd [--check | --requirements | ...] +# 若 PowerShell 执行策略阻止脚本运行,可在当前会话中临时使用: +# Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned + +# 把 PowerShell 会话文化传给 Python(供 manage_templates.py 简繁提示本地化) +if (-not $env:LANG) { $env:LANG = $PSCulture } + +# 让 PowerShell 以 UTF-8 解码 Python 子进程输出(zh-CN Windows 默认 GBK,会乱码/报错) +$env:PYTHONUTF8 = "1" +$env:PYTHONIOENCODING = "utf-8" +$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 +$InputEncoding = [System.Text.Encoding]::UTF8 + +# 候选 Python 解析器:优先仓库 venv,其次 py、python +@( + @{ + Command = (Join-Path $PSScriptRoot "..\.venv\Scripts\python.exe"); + Args = @() + } + @{ + Command = "py"; + Args = @("-3") + } + @{ + Command = "python"; + Args = @() + } +) | Where-Object { Get-Command $_.Command -ErrorAction SilentlyContinue } | Select-Object -First 1 | ForEach-Object { + if (-not $_) { + $message = if ([System.Globalization.CultureInfo]::CurrentUICulture.Name.ToLowerInvariant() -match '^(zh-(hk|mo|tw)|zh-hant)') { + '找不到 Python。請先安裝 Python 3,並確保 py 或 python 在 PATH 中。' + } + else { + '未找到 Python。请先安装 Python 3,并确保 py 或 python 在 PATH 中。' + } + Write-Error $message + exit 1 + } + + $scriptArgs = $_.Args + @(Join-Path $PSScriptRoot "manage_templates.py") + @($args) + & $_.Command @scriptArgs +} +exit $LASTEXITCODE diff --git a/script/manage_templates.py b/script/manage_templates.py new file mode 100644 index 000000000..5b56882e2 --- /dev/null +++ b/script/manage_templates.py @@ -0,0 +1,273 @@ +#!/usr/bin/env python3 +""" +多语言文件管理:验证 + 生成,一站式。 + +用法: + python script/manage_templates.py # 验证通过后生成所有文件 + python script/manage_templates.py --check # 仅验证,不生成 + python script/manage_templates.py --doc-dir DIR # 文档输出到指定根目录(供钩子比对) +""" + +import argparse +import os +import re +import sys +from pathlib import Path +from typing import Any + + +SCRIPT = Path(__file__).name + + +def _tr(text: str) -> str: + """简体 → 繁体 提示文案(按终端文化设置);非繁体环境原样返回。""" + lang = (os.environ.get("LANG") or os.environ.get("LC_ALL") or "").lower() + if not lang and sys.platform == "win32": + import ctypes + lang = "zh_hant" if ctypes.windll.kernel32.GetConsoleOutputCP() == 950 else "zh_hans" + if not lang.replace("-", "_").startswith(("zh_tw", "zh_hk", "zh_mo", "zh_hant")): + return text + for s, t in (("通过", "通過"), ("个问题", "個問題"), ("文档", "文檔"), + ("不纯", "不純"), ("当前版本过低", "目前版本過低"), ("已跳过", "已跳過"), + ("文件", "檔案"), ("含简体字", "含簡體字"), ("含繁体字", "含繁體字"), + ("为空", "為空")): + text = text.replace(s, t) + return text + + +# ══════════════════════════════════════════════════════════════════════ +# 验证 +# ══════════════════════════════════════════════════════════════════════ + +def _check_node(node: Any, path: str, s2tw: Any, t2s: Any, missing: list[str], impure: list[str]) -> None: + """递归检查多语言源文件节点。""" + if isinstance(node, dict): + if "CN" in node and "TW" in node and len(node) == 2: # type: ignore[arg-type] + cn, tw = node["CN"], node["TW"] # type: ignore[assignment] + for val, label in ( # type: ignore[assignment] + (cn, "CN"), + (tw, "TW") + ): + if not val: + missing.append(f"{path}: {label} 为空") + for val, converter, label in ( # type: ignore[assignment] + (tw, s2tw, "TW"), + (cn, t2s, "CN") + ): + # lang_links 中的语言名称按原语言呈现,跳过纯度检查 + if isinstance(val, str) and val and "lang_links" not in path: + if (text_only := re.sub(r"```.+?```", "", val, flags=re.DOTALL) if "```" in val else val) \ + and (converted := converter(text_only)) != text_only \ + and (diffs := sorted({f"{o}→{n}" for o, n in zip(text_only, converted) if o != n})): + kind = "简体" if label == "TW" else "繁体" + impure.append(f"{path}: {label} 含{kind}字 {diffs}") + return + for key, value in node.items(): # type: ignore[unknown-variable] + _check_node(value, f"{path}.{key}", s2tw, t2s, missing, impure) + elif isinstance(node, list): + for i, item in enumerate(node): # type: ignore[unknown-variable] + _check_node(item, f"{path}[{i}]", s2tw, t2s, missing, impure) + + +# ══════════════════════════════════════════════════════════════════════ +# 生成 +# ══════════════════════════════════════════════════════════════════════ + +def _resolve(node: Any, lang: str) -> Any: + """递归解析,提取指定语言的值。""" + if isinstance(node, dict): + if "CN" in node and "TW" in node and len(node) == 2: # type: ignore[arg-type] + return node[lang] # type: ignore[return-value] + return {key: _resolve(value, lang) for key, value in node.items()} # type: ignore[unknown-variable] + if isinstance(node, list): + return [_resolve(item, lang) for item in node] # type: ignore[unknown-variable] + return node + + +def _generate_requirements(pyproject: Path = Path("pyproject.toml")) -> None: + """从 pyproject.toml 的 dependencies 生成 script/requirements.txt(仅需标准库)。""" + try: + import tomllib # type: ignore[import-not-found] + except ModuleNotFoundError: + print(_tr("⚠️ 需要 Python 3.11+ 才能生成 requirements.txt(当前版本过低),已跳过"), file=sys.stderr) + return + deps = tomllib.loads(pyproject.read_text(encoding="utf-8"))["project"]["dependencies"] + out = Path("script") / "requirements.txt" + out.write_text("".join(f"{d}\n" for d in deps), encoding="utf-8") + print(f"✅ {pyproject.name} → {out}") + + +def _collect_headings(node: Any, depth: int = 0, out: list[tuple[int, str]] | None = None) -> list[tuple[int, str]]: + """递归收集文档标题(## 与 ###,排除更深层级)。""" + if out is None: + out = [] + for key, value in node.items(): # type: ignore[unknown-variable] + if isinstance(value, dict): + first = next(iter(value), None) + if first == "heading": + level = depth + 2 + if level <= 3: + out.append((level, value["heading"])) + body = {k: v for k, v in value.items() if k != "heading"} + if body: + _collect_headings(body, depth + 1, out) + return out + + +# 文档类源文件 → (Jinja 模板名, 输出文件名模式, 输出目录) +# {suffix} 占位:"" = 简体, "_zh-TW" = 繁体 +DOC_TEMPLATES: dict[str, tuple[str, str, Path]] = { + "CONTRIBUTING.yml": ("CONTRIBUTING.md.j2", "CONTRIBUTING{suffix}.md", Path(".")), + "README.yml": ("README.md.j2", "README{suffix}.md", Path(".")), + "vscode-extension-README.yml": ("vscode-extension-README.md.j2", "README{suffix}.md", Path("vscode-extension")), +} + + +def main() -> None: + # Windows 管道重定向时强制 UTF-8,避免 ✅ 等字符触发 GBK UnicodeEncodeError + sys.stdout.reconfigure(encoding="utf-8") # type: ignore[attr-defined] + + parser = argparse.ArgumentParser(description="多语言文件管理:验证 + 生成") + parser.add_argument( + "multilingual_dir", + nargs="?", + default="script/multilingual-docs/", + help="多语言源文件目录(默认: script/multilingual-docs/)" + ) + parser.add_argument( + "output_dir", + nargs="?", + default=".github/ISSUE_TEMPLATE/", + help="模板输出目录(默认: .github/ISSUE_TEMPLATE/)" + ) + parser.add_argument( + "--doc-dir", + default=None, + help="文档输出根目录(默认:各模板的相对输出目录,如 . / vscode-extension)" + ) + parser.add_argument( + "--check", + action="store_true", + help="仅验证,不生成" + ) + parser.add_argument( + "--requirements", + action="store_true", + help="仅从 pyproject.toml 生成 script/requirements.txt(无需 pyyaml/opencc),供安装依赖前使用" + ) + args = parser.parse_args() + + if args.requirements: + _generate_requirements() + return + + import yaml # type: ignore[import-not-found] + + class _TemplateDumper(yaml.Dumper): # type: ignore[misc] + pass + _TemplateDumper.add_representer(str, lambda d, data: d.represent_scalar( # type: ignore[no-untyped-call] + "tag:yaml.org,2002:str", data, + style="|" if "\n" in data else '"' if data and (data[0] in "#&*!{%@`" or data[-1] in ":.}" or ":" in data) else None + )) # type: ignore[no-untyped-call] + template_dumper = _TemplateDumper + + multilingual_dir, output_dir = Path(args.multilingual_dir), Path(args.output_dir) + + import opencc # type: ignore + s2tw, t2s = [opencc.OpenCC(c).convert for c in ("s2tw", "t2s")] # type: ignore[no-untyped-call] + yml_files = list(multilingual_dir.glob("*.yml")) + if not yml_files: + print(_tr(f"在 {multilingual_dir} 中未找到 .yml 文件。"), file=sys.stderr) + sys.exit(1) + + all_missing: list[str] = [] + all_impure: list[str] = [] + + for f in yml_files: + with open(f, "r", encoding="utf-8") as fh: + data = yaml.safe_load(fh) + + missing: list[str] = [] + impure: list[str] = [] + _check_node(data, f.name, s2tw, t2s, missing, impure) + all_missing.extend(missing) + all_impure.extend(impure) + + count = len(missing) + len(impure) + if count: + print(_tr(f"\n❌ {f.name}: {count} 个问题")) + for items, emoji in ( + (missing, "⚠️"), + (impure, "🈴") + ): + for item in items: + print(_tr(f" {emoji} {item}")) + else: + print(_tr(f"✅ {f.name}: 通过")) + + total = len(all_missing) + len(all_impure) + if total: + print(_tr(f"\n共 {total} 个问题({len(all_missing)} 缺失, {len(all_impure)} 不纯)")) + sys.exit(1) + print(_tr("\n✅ 全部通过")) + + if args.check: + return + + for f in sorted(multilingual_dir.glob("*.yml")): + data = yaml.safe_load(f.read_text(encoding="utf-8")) + doc = DOC_TEMPLATES.get(f.name) + for lang, suffix in {"CN": "", "TW": "_zh-TW"}.items(): + resolved = _resolve(data, lang) + comment = { + "CN": f"由 {SCRIPT} 自动生成,请勿手动编辑。来源:{f.name}", + "TW": f"由 {SCRIPT} 自動生成,請勿手動編輯。來源:{f.name}", + }[lang] + if doc: + template_name, out_name, out_dir = doc + base = Path(args.doc_dir) / out_dir if args.doc_dir else out_dir + out = base / out_name.format(suffix=suffix) + # 延迟导入:仅在渲染文档时才需要 jinja2,保证 --requirements/--check 仅用标准库 + from jinja2 import Environment, FileSystemLoader, StrictUndefined + + content = ( + f"\n\n" + # Jinja2 环境:模板从多语言源文件目录加载,缺字段即报错 + + Environment( + loader=FileSystemLoader(multilingual_dir), + undefined=StrictUndefined, + ).get_template(template_name).render(resolved=resolved) + ) + # 自动生成目录树(插入到第一个二级标题之前) + headings = _collect_headings(resolved) + if headings: + toc_lines = ["
", f'{"目录树" if lang == "CN" else "目錄樹"}', "", "#### TOC"] + for level, title in headings: + indent = " " * (level - 2) + slug = title.lower() + slug = re.sub(r"\s+", "-", slug) + slug = re.sub(r"[^\w-]+", "", slug) + slug = re.sub(r"-+", "-", slug) + toc_lines.append(f"{indent}- [{title}](#{slug})") + toc_lines += ["", "
"] + idx = content.find("\n## ") + if idx != -1: + content = content[: idx + 1] + "\n".join(toc_lines) + "\n\n" + content[idx + 1 :] + out.parent.mkdir(parents=True, exist_ok=True) + out.write_text(content, encoding="utf-8") + else: + out = output_dir / f"{f.stem}{suffix}.yml" + out.parent.mkdir(parents=True, exist_ok=True) + with open(out, "w", encoding="utf-8") as fh: + fh.write(f"# {comment}\n") + yaml.dump(resolved, fh, Dumper=template_dumper, + allow_unicode=True, default_flow_style=False, + sort_keys=False, width=120) + print(f"✅ {f.name} → {out.name}") + print(_tr(f"✅ {f.name}: {'文档' if doc else '模板'}生成完成")) + + _generate_requirements() + + +if __name__ == "__main__": + main() diff --git a/script/multilingual-docs/CONTRIBUTING.md.j2 b/script/multilingual-docs/CONTRIBUTING.md.j2 new file mode 100644 index 000000000..3ff7773bc --- /dev/null +++ b/script/multilingual-docs/CONTRIBUTING.md.j2 @@ -0,0 +1,24 @@ +{# 通用递归渲染:结构与层级完全由 YAML 数据(键顺序 + heading 嵌套)推断, + 模板本身不硬编码任何块名/顺序/层级。#} +{%- macro render(node, depth=0) -%} +{%- set ns = namespace(lines=[]) -%} +{%- for key, value in node.items() -%} +{%- if value is mapping and (value.keys() | list | first) == 'heading' -%} +{%- set _ = ns.lines.append('#' * (depth + 2) + ' ' + value['heading']) -%} +{%- set _ = ns.lines.append('') -%} +{%- set body = namespace(d={}) -%} +{%- for k2, v2 in value.items() -%} +{%- if k2 != 'heading' -%}{%- set _ = body.d.update({k2: v2}) -%}{%- endif -%} +{%- endfor -%} +{%- if body.d -%} +{%- set _ = ns.lines.append(render(body.d, depth + 1) | trim) -%} +{%- set _ = ns.lines.append('') -%} +{%- endif -%} +{%- elif value is string -%} +{%- set _ = ns.lines.append(('# ' + value) if key == 'title' else value) -%} +{%- set _ = ns.lines.append('') -%} +{%- endif -%} +{%- endfor -%} +{{ ns.lines | join('\n') -}} +{%- endmacro %} +{{- render(resolved) -}} diff --git a/script/multilingual-docs/CONTRIBUTING.yml b/script/multilingual-docs/CONTRIBUTING.yml new file mode 100644 index 000000000..0be3a0fb3 --- /dev/null +++ b/script/multilingual-docs/CONTRIBUTING.yml @@ -0,0 +1,293 @@ +# 贡献指南 —— 唯一维护来源 +# 由 manage_templates.py 校验并生成 CN/TW 贡献指南。 +# +# 规则: +# - 纯字符串 → CN/TW 共享该值 +# - CN: "简体" / TW: "繁體" → 分语言翻译 +# - 结构字段(链接 URL 等)不翻译,保持原样 +# - 渲染:title→#,顶层字符串→原文;块字段首个子字段为 heading,层级 = 嵌套深度+2 + +top_align_begin:
+ +title: + CN: 贡献指南 + TW: 貢獻指南 + +lang_links: + CN: "**简体中文** · [繁體中文](./CONTRIBUTING_zh-TW.md)" + TW: "[简体中文](./CONTRIBUTING.md) · **繁體中文**" + +top_align_end:
+ +setup_env: + heading: + CN: 设置开发环境 + TW: 設置開發環境 + steps: + CN: | + 1. [克隆仓库](https://docs.github.com/repositories/creating-and-managing-repositories/cloning-a-repository) + 1. 进入仓库目录: + [Bash](https://www.gnu.org/software/bash/manual/bash.html#index-cd 'cd') · + [Zsh](https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html 'cd') · + [Fish](https://fishshell.com/docs/current/cmds/cd.html 'cd') · + [C Shell](https://www.freebsd.org/cgi/man.cgi?query=cd&sektion=1 'cd') · + [Windows 命令提示符](https://learn.microsoft.com/windows-server/administration/windows-commands/cd 'cd') · + [PowerShell](https://learn.microsoft.com/powershell/module/microsoft.powershell.management/set-location 'Set-Location') · + [Windows 文件资源管理器](https://windowsforum.com/windows-news.4/bridge-file-explorer-and-terminal-in-windows-11-for-faster-workflows.389155/#_xfUid-1-1781860855 '在终端中打开') + 1. [创建和激活虚拟环境](https://docs.python.org/3/library/venv.html) + 1. 安装依赖: + ```bash + python script/manage_templates.py --requirements + pip install -r script/requirements.txt + ``` + 1. 启用提交前的钩子(提交前自动验证多语言源文件): + ```bash + git config core.hooksPath .githooks + ``` + TW: | + 1. [克隆倉庫](https://docs.github.com/repositories/creating-and-managing-repositories/cloning-a-repository) + 1. 進入倉庫目錄: + [Bash](https://www.gnu.org/software/bash/manual/bash.html#index-cd 'cd') · + [Zsh](https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html 'cd') · + [Fish](https://fishshell.com/docs/current/cmds/cd.html 'cd') · + [C Shell](https://www.freebsd.org/cgi/man.cgi?query=cd&sektion=1 'cd') · + [Windows 命令提示字元](https://learn.microsoft.com/windows-server/administration/windows-commands/cd 'cd') · + [PowerShell](https://learn.microsoft.com/powershell/module/microsoft.powershell.management/set-location 'Set-Location') · + [Windows 檔案總管](https://windowsforum.com/windows-news.4/bridge-file-explorer-and-terminal-in-windows-11-for-faster-workflows.389155/#_xfUid-1-1781860855 '在終端中打開') + 1. [創建和啟動虛擬環境](https://docs.python.org/3/library/venv.html) + 1. 安裝依賴: + ```bash + python script/manage_templates.py --requirements + pip install -r script/requirements.txt + ``` + 1. 啟用提交前的掛鉤(提交前自動驗證多語言源文件): + ```bash + git config core.hooksPath .githooks + ``` + +contribute: + heading: + CN: 贡献方式 + TW: 貢獻方式 + intro_text: + CN: | + 欢迎通过以下方式参与贡献: + + 1. 完善词库翻译(编辑 [`locals.js`](locals.js)) + 1. 提交议题报告,参与话题讨论 + 1. 改进代码逻辑 + TW: | + 歡迎通過以下方式參與貢獻: + + 1. 完善詞庫翻譯(編輯 [`locals.js`](locals.js)) + 1. 提交議題報告,參與話題討論 + 1. 改進程式碼邏輯 + badge: | + [![PR Welcome](https://img.shields.io/badge/🤯_pr_welcome-%E2%86%92-ffcb47?labelColor=black&style=for-the-badge)](https://github.com/maboloshi/github-chinese/pulls) + references: + heading: + CN: 翻译参考资源 + TW: 翻譯參考資源 + items: + CN: | + 1. [Pro Git 第二版 简体中文](https://git-scm.com/book/zh-tw/v2) + 1. [Pro Git: 翻译约定](https://github.com/progit/progit2-zh/blob/master/TRANSLATION_NOTES.asc) + 1. [Git 官方软件包的简体中文翻译](https://github.com/git/git/blob/master/po/zh_CN.po) + 1. [GitHub 术语表](https://docs.github.com/get-started/learning-about-github/github-glossary) + 1. **[CSS 选择器](https://developer.mozilla.org/docs/Web/CSS/Reference/Selectors)用于编写忽略规则** + TW: | + 1. [Pro Git 第二版 繁體中文](https://git-scm.com/book/zh-tw/v2) + 1. [Pro Git: 翻譯約定](https://github.com/progit/progit2-zh-tw/blob/master/TRANSLATION_NOTES.asc) + 1. [Git 官方軟體包的繁體中文翻譯](https://github.com/git/git/blob/master/po/zh_TW.po) + 1. [GitHub 詞彙表](https://docs.github.com/get-started/learning-about-github/github-glossary) + 1. **[CSS 選擇器](https://developer.mozilla.org/docs/Web/CSS/Reference/Selectors)用於編寫忽略規則** + +workflow: + heading: + CN: 多语言文档工作流 + TW: 多語言文件工作流 + auto: + heading: + CN: 自动生成 + TW: 自動生成 + intro: + CN: | + [README.md](README.md '仓库自述')、[vscode-extension/README.md](vscode-extension/README.md 'VS Code 扩展自述')、议题模板、[CONTRIBUTING.md](CONTRIBUTING.md '贡献指南')均采用**多语言源文件驱动**模式,由 `manage_templates.py` 从 YAML 源文件统一生成简体/繁体版本: + + ```mermaid + flowchart LR + subgraph Sources["多语言源文件 script/multilingual-docs/"] + S1["bug-提交.yml"] + S2["CONTRIBUTING.yml"] + S3["README.yml"] + S4["vscode-extension-README.yml"] + end + S1 --> B["manage_templates.py"] + S2 --> B + S3 --> B + S4 --> B + B --> C["议题模板 .github/ISSUE_TEMPLATE/*.yml"] + B --> D["贡献指南 CONTRIBUTING*.md"] + B --> E["仓库自述 README*.md"] + B --> F["扩展自述 vscode-extension/README*.md"] + C --> G["生成文件不入库"] + D --> G + E --> G + F --> G + G --> H["云端 CI 默认分支自动生成并提交"] + ``` + TW: | + [README.md](README.md '倉庫自述')、[vscode-extension/README.md](vscode-extension/README.md 'VS Code 擴展自述')、議題模板、[CONTRIBUTING.md](CONTRIBUTING.md '貢獻指南')均採用**多語言源文件驅動**模式,由 `manage_templates.py` 從 YAML 源文件統一生成簡體/繁體版本: + + ```mermaid + flowchart LR + subgraph Sources["多語言源文件 script/multilingual-docs/"] + S1["bug-提交.yml"] + S2["CONTRIBUTING.yml"] + S3["README.yml"] + S4["vscode-extension-README.yml"] + end + S1 --> B["manage_templates.py"] + S2 --> B + S3 --> B + S4 --> B + B --> C["議題模板 .github/ISSUE_TEMPLATE/*.yml"] + B --> D["貢獻指南 CONTRIBUTING*.md"] + B --> E["倉庫自述 README*.md"] + B --> F["擴展自述 vscode-extension/README*.md"] + C --> G["生成文件不入庫"] + D --> G + E --> G + F --> G + G --> H["雲端 CI 預設分支自動生成並提交"] + ``` + maintain: + heading: + CN: 维护 + TW: 維護 + steps: + CN: | + 1. 编辑源文件 + 1. 验证并预览:提交时钩子会自动验证源文件并检查生成文件一致性(过时或手动修改会阻止提交);本地可提前验证或生成到工作区预览。 + ```bash + python script/manage_templates.py --check + python script/manage_templates.py + ``` + 或 Windows 用包装脚本 `script/manage.ps1`(自动选 venv Python 且 UTF-8 输出不乱码): + ```powershell + .\script\manage.ps1 --check + ``` + 命令提示符则通过 PowerShell 调用: + ```cmd + powershell -ExecutionPolicy RemoteSigned -File script\manage.ps1 --check + ``` + 如果使用 VS Code,可启用 [GitHub Issue Template Preview](https://marketplace.visualstudio.com/items?itemName=ReesPozzi.github-issue-template-preview)。 + 1. [提交](https://docs.github.com/pull-requests/how-tos/commit-changes) → 提交前的钩子自动验证源文件,并检测手动修改的生成文件;生成文件**不入库** + 1. [推送](https://docs.github.com/get-started/using-git/pushing-commits-to-a-remote-repository '推送提交到远程仓库') → [拉取请求](https://docs.github.com/pull-requests/how-tos/create-pull-requests/creating-a-pull-request '创建拉取请求') → [持续集成](https://docs.github.com/actions/get-started/continuous-integration '持续集成')验证与钩子测试 → 合并到默认分支 → **云端自动生成并提交**简体/繁体文档与模板 + TW: | + 1. 編輯源檔案 + 1. 驗證並預覽:提交時掛鉤會自動驗證源檔案並檢查生成檔案一致性(過時或手動修改會阻止提交);本地可提前驗證或生成到工作區預覽。 + ```bash + python script/manage_templates.py --check + python script/manage_templates.py + ``` + 或 Windows 用包裝腳本 `script/manage.ps1`(自動選 venv Python 且 UTF-8 輸出不亂碼): + ```powershell + .\script\manage.ps1 --check + ``` + 命令提示字元則透過 PowerShell 呼叫: + ```cmd + powershell -ExecutionPolicy RemoteSigned -File script\manage.ps1 --check + ``` + 如果使用 VS Code,可啟用 [GitHub Issue Template Preview](https://marketplace.visualstudio.com/items?itemName=ReesPozzi.github-issue-template-preview)。 + 1. [提交](https://docs.github.com/pull-requests/how-tos/commit-changes) → 提交前的掛鉤自動驗證源檔案,並檢測手動修改的生成檔案;生成檔案**不入庫** + 1. [推送](https://docs.github.com/get-started/using-git/pushing-commits-to-a-remote-repository '推送提交至遠端倉儲') → [拉取請求](https://docs.github.com/pull-requests/how-tos/create-pull-requests/creating-a-pull-request '創建拉取請求') → [持續集成](https://docs.github.com/actions/get-started/continuous-integration '持續集成')驗證與掛鉤測試 → 合併到預設分支 → **雲端自動生成並提交**簡體/繁體文件與模板 + +windows_dev: + heading: + CN: Windows 开发者注意事项 + TW: Windows 開發者注意事項 + warning: + CN: | + > [!WARNING] + > 本仓库的开发、测试与云端持续集成(CI)[工作流程](.github\workflows)基于 Linux(`ubuntu-latest`)。 + > + > Windows 开发者若只在本机测试,可能踩到 Linux 才有、CI 才会暴露的坑。 + TW: | + > [!WARNING] + > 本倉庫的開發、測試與雲端持續整合(CI)[工作流程](.github\workflows)基於 Linux(`ubuntu-latest`)。 + > + > Windows 開發者若只在本機測試,可能踩到 Linux 才有、CI 才會暴露的坑。 + tips: + CN: | + > [!TIP] + > 建议 Windows 开发者在[适用于 Linux 的 Windows 子系统](https://learn.microsoft.com/windows/wsl/)中测试,以获得最接近云端 CI 的环境。 + TW: | + > [!TIP] + > 建議 Windows 開發者在[適用於 Linux 的 Windows 子系統](https://learn.microsoft.com/windows/wsl/)中測試,以獲得最接近雲端 CI 的環境。 + known_issues: + heading: + CN: 常见坑 + TW: 常見坑 + body: + CN: | + - **钩子可执行位**:Linux 上 git 严格[要求](https://git-scm.com/docs/api-run-command/2.0.5#Documentation/technical/api-run-command.txt-runhook 'run_hook')钩子有 `chmod +x`,否则报 "hook was ignored because it's not set as executable";Windows 不检查,本地正常但 CI 失败。 + - **CRLF/LF 行尾**:bash 脚本(`.githooks/pre-commit`、`test/*.sh`)应使用 [LF 行尾](https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/basedefs/V1_chap03.html#tag_03_185 'The Open Group Base Specifications Issue 8/IEEE Std 1003.1-2024, 3.185'),CRLF 会导致解析失败;[`.gitattributes`](.gitattributes) 已用 `eol=lf` 强制。 + - **钩子 stdin**:pre-commit 钩子的 stdin 默认是 `/dev/null`,交互读取输入需从 `/dev/tty`;非交互环境用 `GIT_HOOK_NONINTERACTIVE=1` 跳过询问。 + - **[PEP 668](https://peps.python.org/pep-0668/)**:Ubuntu/WSL 的系统 Python 受保护,直接 `pip install` 报 `externally-managed-environment`,请用 venv(见下)。 + TW: | + - **鉤子可執行位**:Linux 上 git 嚴格[要求](https://git-scm.com/docs/api-run-command/2.0.5#Documentation/technical/api-run-command.txt-runhook 'run_hook')掛鉤有 `chmod +x`,否則報 "hook was ignored because it's not set as executable";Windows 不檢查,本地正常但 CI 失敗。 + - **CRLF/LF 行尾**:bash 腳本(`.githooks/pre-commit`、`test/*.sh`)應使用 [LF 行尾](https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/basedefs/V1_chap03.html#tag_03_185 'The Open Group Base Specifications Issue 8/IEEE Std 1003.1-2024, 3.185'),CRLF 會導致解析失敗;[`.gitattributes`](.gitattributes) 已用 `eol=lf` 強制。 + - **鉤子 stdin**:pre-commit 鉤子的 stdin 預設是 `/dev/null`,互動讀取輸入需從 `/dev/tty`;非互動環境用 `GIT_HOOK_NONINTERACTIVE=1` 跳過詢問。 + - **[PEP 668](https://peps.python.org/pep-0668/)**:Ubuntu/WSL 的系統 Python 受保護,直接 `pip install` 報 `externally-managed-environment`,請用 venv(見下)。 + wsl_setup: + heading: + CN: 在 WSL 中准备测试环境 + TW: 在 WSL 中準備測試環境 + body: + CN: | + 生成文件不入库(由云端 CI 自动生成),开发者提交源文件即可。要在 WSL 中本地验证,可参考以下步骤(依赖统一从 [`script/requirements.txt`](script/requirements.txt) 安装): + + ```bash + # 安装官方 Python 工具(需要 sudo 密码) + sudo apt update + sudo apt install -y python3-pip python3-venv + + # 克隆/复制仓库到 WSL 原生文件系统(比 /mnt/c 更接近云端 CI) + cd ~ + git clone https://github.com/maboloshi/github-chinese.git + cd github-chinese + + # 创建 venv 并从项目依赖清单安装 + python3 -m venv .venv-wsl + .venv-wsl/bin/pip install -r script/requirements.txt + + # 让钩子与测试使用 venv 的 Python + export PATH="$(pwd)/.venv-wsl/bin:$PATH" + + # 运行钩子测试 + bash test/test_pre_commit_hook.sh + ``` + TW: | + 生成檔案不入庫(由雲端 CI 自動生成),開發者提交源檔案即可。要在 WSL 中本地驗證,可參考以下步驟(依賴統一從 [`script/requirements.txt`](script/requirements.txt) 安裝): + + ```bash + # 安裝官方 Python 工具(需要 sudo 密碼) + sudo apt update + sudo apt install -y python3-pip python3-venv + + # 克隆/複製倉庫到 WSL 原生檔案系統(比 /mnt/c 更接近雲端 CI) + cd ~ + git clone https://github.com/maboloshi/github-chinese.git + cd github-chinese + + # 建立 venv 並從專案依賴清單安裝 + python3 -m venv .venv-wsl + .venv-wsl/bin/pip install -r script/requirements.txt + + # 讓掛鉤與測試使用 venv 的 Python + export PATH="$(pwd)/.venv-wsl/bin:$PATH" + + # 執行掛鉤測試 + bash test/test_pre_commit_hook.sh + ``` diff --git a/script/multilingual-docs/README.md.j2 b/script/multilingual-docs/README.md.j2 new file mode 100644 index 000000000..3ff7773bc --- /dev/null +++ b/script/multilingual-docs/README.md.j2 @@ -0,0 +1,24 @@ +{# 通用递归渲染:结构与层级完全由 YAML 数据(键顺序 + heading 嵌套)推断, + 模板本身不硬编码任何块名/顺序/层级。#} +{%- macro render(node, depth=0) -%} +{%- set ns = namespace(lines=[]) -%} +{%- for key, value in node.items() -%} +{%- if value is mapping and (value.keys() | list | first) == 'heading' -%} +{%- set _ = ns.lines.append('#' * (depth + 2) + ' ' + value['heading']) -%} +{%- set _ = ns.lines.append('') -%} +{%- set body = namespace(d={}) -%} +{%- for k2, v2 in value.items() -%} +{%- if k2 != 'heading' -%}{%- set _ = body.d.update({k2: v2}) -%}{%- endif -%} +{%- endfor -%} +{%- if body.d -%} +{%- set _ = ns.lines.append(render(body.d, depth + 1) | trim) -%} +{%- set _ = ns.lines.append('') -%} +{%- endif -%} +{%- elif value is string -%} +{%- set _ = ns.lines.append(('# ' + value) if key == 'title' else value) -%} +{%- set _ = ns.lines.append('') -%} +{%- endif -%} +{%- endfor -%} +{{ ns.lines | join('\n') -}} +{%- endmacro %} +{{- render(resolved) -}} diff --git a/script/multilingual-docs/README.yml b/script/multilingual-docs/README.yml new file mode 100644 index 000000000..3b9d82dad --- /dev/null +++ b/script/multilingual-docs/README.yml @@ -0,0 +1,615 @@ +# 仓库自述 —— 唯一维护来源 +# 由 manage_templates.py 校验并生成 CN/TW 仓库自述。 +# TW 缺失版本(v1.9.4.2 / v1.9.4.1 / v1.9.4)与结构差异处为 opencc 转换草案,供人工校对。 + +# ── 头部(统一居中样式) ── +top_align_begin:
+ +title: + CN: "[GitHub 中文化插件][github-project-link]" + TW: "[GitHub 中文化插件][github-project-link]" + +slogan: + CN: "> 让 GitHub 界面全面中文化 | 源自 [52cik/github-hans](https://github.com/52cik/github-hans)" + TW: "> 讓 GitHub 界面全面中文化 | 源自 [52cik/github-hans](https://github.com/52cik/github-hans)" + +lang_links: + CN: "**简体中文** · [繁體中文](./README_zh-TW.md) · [反馈问题][github-issues-link]" + TW: "[简体中文](./README.md) · **繁體中文** · [反饋問題][github-issues-link]" + +badges: |- + + + [![GitHub issues][github-issues-shield]][github-issues-link] + [![GitHub stars][github-stars-shield]][github-stars-link] + [![GitHub forks][github-forks-shield]][github-forks-link] + [![license GPL-3.0][github-license-shield]][github-license-link] + [![GreasyFork installs][greasyFork-shield]][greasyFork-link] + +hellogithub: |- + + + + + Featured|HelloGitHub + + + +top_align_end:
+ +warning: + CN: |- + > [!warning] + > 本项目从未发布至 GitCode,如您发现请截图并保留证据 + TW: |- + > [!warning] + > 本項目從未發佈至 GitCode,如您發現請截圖並保留證據 + +# ── 功能特性 ── +features: + heading: + CN: 🌟 功能特性 + TW: 🌟 功能特性 + items: + CN: |- + - [x] 全面中文化 GitHub 界面元素(菜单栏、标题、按钮等) + - [x] 智能正则匹配功能 + - [x] 支持项目描述的人机翻译 + - [x] 自动本地化时间元素 + - [x] 持续更新词库 + TW: |- + - [x] 全面中文化 GitHub 界面元素(菜單欄、標題、按鈕等) + - [x] 智能正則匹配功能 + - [x] 支持項目描述的人機翻譯 + - [x] 自動本地化時間元素 + - [x] 持續更新詞庫 + +# ── 兼容环境 ── +compat: + heading: + CN: 🌐 兼容环境 + TW: 🌐 兼容環境 + table: + CN: |- + 浏览器类型 | 支持的脚本管理器 + :------------------: | :---------------: + Chrome / Chromium 内核 | [Tampermonkey][Tampermonkey], [Violentmonkey][Violentmonkey] + Safari(全平台) | [Tampermonkey][Tampermonkey], [Macaque][Macaque], [Stay][Stay] + Firefox / Gecko 内核 | [Tampermonkey][Tampermonkey], [Violentmonkey][Violentmonkey] + Via(Android) | 内置管理器 + VS Code 集成浏览器 | [Integrated Browser Extensions][Integrated Browser Extensions](扩展的源码仓库已删除) + TW: |- + 瀏覽器類型 | 支持的腳本管理器 + :------------------: | :---------------: + Chrome / Chromium 內核 | [Tampermonkey][Tampermonkey], [Violentmonkey][Violentmonkey] + Safari(全平臺) | [Macaque][Macaque], [Stay][Stay] + Firefox / Gecko 內核 | [Tampermonkey][Tampermonkey], [Violentmonkey][Violentmonkey] + Via(Android) | 內置管理器 + +# ── 安装指南 ── +install: + heading: + CN: 💻 安装指南 + TW: 💻 安裝指南 + browser: + heading: + CN: 浏览器(Tampermonkey) + TW: 瀏覽器(Tampermonkey) + steps: + CN: |- + 1. 安装用户脚本管理器: + - 推荐:[Tampermonkey][Tampermonkey] + 1. **基于 Chrome / Chromium 内核浏览器:** + 1. 务必开启 “扩展程序” 管理中的 **“开发者模式”**[^1] + 1. 务必开启 “扩展程序” 管理中脚本管理器扩展的 **“允许运行用户脚本”** + 1. 具体可参考 [Tampermonkey 官方指引](https://www.tampermonkey.net/faq.php#Q209) + 1. 选择安装源: + - [GitHub 源【开发版】][main.user.js] + - [南大镜像源【开发版】][main(nju.edu).user.js] + - [GreasyFork 源【稳定版】][main(greasyfork).user.js] + 1. 刷新页面后,插件即可生效 + 1. 必要时,重启浏览器 + + [^1]: [Chrome 切换到 Manifest V3后,使用问题](https://github.com/maboloshi/github-chinese/issues/234) + + > [!NOTE] + > **版本说明**: + > - 🚀 开发版:实时更新,每周五自动更新词库 + > - 🛡️ 稳定版:每周一同步开发版词库,更稳定 + TW: |- + 1. 安裝用戶腳本管理器: + - 推薦:[Tampermonkey][Tampermonkey] + 1. **基於 Chrome / Chromium 內核瀏覽器:** + 1. 務必開啟 「擴展程序」 管理中的 **「開發者模式」**[^1] + 1. 務必開啟 「擴展程序」 管理中腳本管理器擴展的 **「允許運行用戶腳本」** + 1. 具體可參考 [Tampermonkey 官方指引](https://www.tampermonkey.net/faq.php#Q209) + 1. 選擇安裝源: + - [GitHub 源【開發版】][main_zh-TW.user.js] + 1. 刷新頁面後,插件即可生效 + 1. 必要時,重啟瀏覽器 + + [^1]: [Chrome 切換到 Manifest V3後,使用問題](https://github.com/maboloshi/github-chinese/issues/234) + + > [!NOTE] + > **版本說明**: + > - 🚀 開發版:實時更新,每週五自動更新詞庫 + > - 🛡️ 穩定版:每週一同步開發版詞庫,更穩定 + vscode: + heading: + CN: VS Code 集成浏览器(Integrated Browser Extensions) + TW: VS Code 整合式瀏覽器(Integrated Browser Extensions) + text: + CN: 请参考[扩展的自述文件](vscode-extension/README.md)。 + TW: 請參考[擴展的自述文件](vscode-extension/README.md)。 + +# ── 本地调试 ── +debug: + heading: + CN: 🔧 本地调试 + TW: 🔧 本地調試 + steps: + CN: |- + 1. 安装 [Tampermonkey][Tampermonkey],并启用 “允许访问文件网址”。 + 1. 下载词库文件到本地(如:`D:\github-chinese\locals.js`) + 1. 在脚本管理器中修改引用路径: + ```js + // 原始路径 + // @require https://raw.githubusercontent.com/... + + // 修改为 + // @require file:///D:/github-chinese/locals.js + ``` + 1. 刷新页面生效 + + > [!IMPORTANT] + > **若无效:** + > 1. 进入 [Tampermonkey][Tampermonkey] 插件`设置页` + > 1. 将 `通用 - 配置模式` 设置为`高级`,进入高级设置模式 + > 1. 找到 `安全 - 允许脚本访问本地文件` 并设置为 `外部(@require 和 @resource)` + + > [!TIP] + > 💡 **温馨提示:** 您可以将词库文件拖拽至浏览器地址栏,复制路径直接使用。 + TW: |- + 1. 安裝 [Tampermonkey][Tampermonkey],並啟用 “允許訪問文件網址”。 + 1. 下載詞庫文件到本地(如:`D:\github-chinese\locals.js`) + 1. 在腳本管理器中修改引用路徑: + ```js + // 原始路徑 + // @require https://raw.githubusercontent.com/... + + // 修改為 + // @require file:///D:/github-chinese/locals.js + ``` + 1. 刷新頁面生效 + + > [!IMPORTANT] + > **若無效:** + > 1. 進入 [Tampermonkey][Tampermonkey] 插件`設置頁` + > 1. 將 `通用 - 配置模式` 設置為`高級`,進入高級設置模式 + > 1. 找到 `安全 - 允許腳本訪問本地文件` 並設置為 `外部(@require 和 @resource)` + + > [!TIP] + > 💡 **溫馨提示:** 您可以將詞庫文件拖拽至瀏覽器地址欄,複製路徑直接使用。 + back_to_top: |- +
+ + [![][back-to-top]](#readme-top) + +
+ +# ── 更新日志 ── +changelog: + heading: + CN: 🔄 更新日志 + TW: 🔄 更新日誌 + latest: + heading: + CN: 最新版本 + TW: 最新版本 + v1944: + heading: + CN: v1.9.4.4 (2026-06-20) + TW: v1.9.4.4 (2026-06-20) + items: + CN: |- + 1. 兼容修复`1.9.2.4`,`1.9.4.4`: + - 区分 React GlobalNav 与页面主体共享的 Primer 弹层,恢复下拉菜单即时、完整翻译。 + TW: |- + 1. 相容修復`1.9.2.4`,`1.9.4.4`: + - 區分 React GlobalNav 與頁面主體共用的 Primer 彈層,恢復下拉選單即時、完整翻譯。 + v1943: + heading: + CN: v1.9.4.3 (2026-06-17) + TW: v1.9.4.3 (2026-06-17) + items: + CN: |- + 1. 兼容修复`1.9.2.3`,`1.9.4.3`: + - 收窄 React 搜索模块忽略范围,恢复仓库议题页和搜索页主体区域翻译。 + TW: |- + 1. 相容修復`1.9.2.3`,`1.9.4.3`: + - 收窄 React 搜尋模組忽略範圍,恢復倉庫議題頁和搜尋頁主體區域翻譯。 + v1942: + heading: + CN: v1.9.4.2 (2026-06-17) + TW: v1.9.4.2 (2026-06-17) + items: + CN: |- + 1. 兼容修复`1.9.2.2`,`1.9.4.2`: + - 在保持 React 头部搜索框稳定的前提下,恢复头部导航、菜单、搜索弹层和提示翻译。 + TW: |- + 1. 相容修復`1.9.2.2`,`1.9.4.2`: + - 在保持 React 頭部搜索框穩定的前提下,恢復頭部導航、菜單、搜索彈層和提示翻譯。 + v1941: + heading: + CN: v1.9.4.1 (2026-06-16) + TW: v1.9.4.1 (2026-06-16) + items: + CN: |- + 1. 临时修复`1.9.2`,`1.9.4`: + - 关于 GitHub 引入 React 机制导致头部搜索框消失。副作用整个头部导航全部加入忽略规则,无法翻译。 + TW: |- + 1. 臨時修復`1.9.2`,`1.9.4`: + - 關於 GitHub 引入 React 機制導致頭部搜索框消失。副作用整個頭部導航全部加入忽略規則,無法翻譯。 + v1940: + heading: + CN: v1.9.4 (2026-05-17) + TW: v1.9.4 (2026-05-17) + items: + CN: |- + 1. 代码重构: + - 全面结构化重组:抽离配置常量 `CONFIG`、状态管理器 `State` + - 引入 `safe()` 错误边界包裹关键函数,便于排错 + - 函数拆分细化:`watchUpdate` → `setupMutationObserver` + `processMutations`,`transDesc` → `handleTransClick` + `requestRemoteTrans` + `showTransResult` + - `processMutations` 祖先去重:同一批 mutation 中后代节点不再重复遍历 + 1. 新增功能: + - 翻译结果 UI 暗色主题适配(CSS 变量 + `prefers-color-scheme` 媒体查询),使用 `GM_addStyle` 插入 + - 未命中词条管理器 `MissedTermsManager`(记录、导出 JSON、清空、统计、菜单) + - 开发者模式(`CONFIG.DEV`)控制未命中词条菜单显隐 + - Tampermonkey `onurlchange` 事件支持(`setupUrlChangeListener`) + 1. 修复: + - 修复翻译 API 响应 XSS 漏洞:`innerHTML` 模板拼接改为 `textContent` 安全赋值(由 #692 报告) + - 修复 TreeWalker 过滤器在 `ignoreSelectors` 为空时抛出 `SyntaxError` + - 修复翻译按钮可能重复添加的问题(`nextSibling` 空值检查) + - 修复 `RELATIVE-TIME` shadowRoot 为 null 时的崩溃 + - 修复从未识别页面离开后 `State.pageConfig` 未清空,导致旧配置残留的问题 + 1. 性能优化:减少无效迭代,消除不必要的 DOM 遍历 + TW: |- + 1. 代碼重構: + - 全面結構化重組:抽離配置常量 `CONFIG`、狀態管理器 `State` + - 引入 `safe()` 錯誤邊界包裹關鍵函數,便於排錯 + - 函數拆分細化:`watchUpdate` → `setupMutationObserver` + `processMutations`,`transDesc` → `handleTransClick` + `requestRemoteTrans` + `showTransResult` + - `processMutations` 祖先去重:同一批 mutation 中後代節點不再重複遍歷 + 1. 新增功能: + - 翻譯結果 UI 暗色主題適配(CSS 變量 + `prefers-color-scheme` 媒體查詢),使用 `GM_addStyle` 插入 + - 未命中詞條管理器 `MissedTermsManager`(記錄、導出 JSON、清空、統計、菜單) + - 開發者模式(`CONFIG.DEV`)控制未命中詞條菜單顯隱 + - Tampermonkey `onurlchange` 事件支持(`setupUrlChangeListener`) + 1. 修復: + - 修復翻譯 API 響應 XSS 漏洞:`innerHTML` 模板拼接改為 `textContent` 安全賦值(由 #692 報告) + - 修復 TreeWalker 過濾器在 `ignoreSelectors` 為空時拋出 `SyntaxError` + - 修復翻譯按鈕可能重複添加的問題(`nextSibling` 空值檢查) + - 修復 `RELATIVE-TIME` shadowRoot 為 null 時的崩潰 + - 修復從未識別頁面離開後 `State.pageConfig` 未清空,導致舊配置殘留的問題 + 1. 性能優化:減少無效迭代,消除不必要的 DOM 遍歷 + v193: + heading: + CN: v1.9.3 (2024-08-18) + TW: v1.9.3 (2024-08-18) + items: + CN: |- + 1. 新增功能:通过设置中文环境,自动本地化时间元素,仅保留`on`开头的时间正则,并停用时间元素监视 + 1. 优化突变翻译处理: + - 引入`characterDataPage`规则,对特定页面启用`筛选字符数据`的变更 + - 引入`ignoreMutationSelectorPage`规则,忽略特定突变元素 + 1. 合并`reIgnoreClass,reIgnoreItemprop,ignoreId,ignoreTag`为`ignoreSelectorPage`规则,处理全局及特定页面,忽略特定元素 + 1. 引入全局缓存模式,减少重复构建包括不限于基于`page`变化的忽略规则、正则规则数组等 + 1. 调整:更新讯飞听见翻译引擎v2.0 + 1. 优化:梳理、优化脚本 + 1. 调整:调整词库语言代码为`zh-CN`, 与环境语言设置一致 + TW: |- + 1. 新增功能:通過設置中文環境,自動本地化時間元素,僅保留`on`開頭的時間正則,並停用時間元素監視 + 1. 優化突變翻譯處理: + - 引入`characterDataPage`規則,對特定頁面啟用`篩選字符數據`的變更 + - 引入`ignoreMutationSelectorPage`規則,忽略特定突變元素 + 1. 合併`reIgnoreClass,reIgnoreItemprop,ignoreId,ignoreTag`為`ignoreSelectorPage`規則,處理全局及特定頁面,忽略特定元素 + 1. 引入全局緩存模式,減少重複構建包括不限於基於`page`變化的忽略規則、正則規則數組等 + 1. 調整:更新訊飛聽見翻譯引擎v2.0 + 1. 優化:梳理、優化腳本 + 1. 調整:調整詞庫語言代碼為`zh-CN`, 與環境語言設置一致 + history: |- +
查看更多历史版本 + + #### v1.9.2 (2024-06-14) + + 1. 适配`www.githubstatus.com` + 1. 适配`skills.github.com` + + #### v1.9.1 (2024-05-23) + + 1. 更新`切换正则功能按钮` + + #### v1.9.0 (2023-12-09) + + 1. 重新定义版本号规则, 如`1.9.0-2023-12-09`。 + - `1.9.0`: 主版本号(由项目所有者更新) + - `2023-12-09`:`词库`发布版本号(由 GitHub Action 自动更新) + 1. 加强: [GitHub 源【开发版】][main.user.js]每周一凌晨自动更新`词库`发布版本号 + 1. 加强: [GreasyFork 源【稳定版】][main(greasyfork).user.js]每周五凌晨自动更新`词库`发布版本号, 词库内容同上一次[GitHub 源【开发版】][main.user.js] + 1. 加强:在 `README.md` 中自动更新贡献者头像 + 1. 更新: 忽略规则, 词条等 + + #### v1.8.5 (2023-08-31) + + 1. 优化: `transDesc 函数`代码 + 1. 修复: 重复添加`translate-me`翻译按钮 + 1. 加强:`watchUpdate 函数`新增节点文本更新的情况 + 1. 调整: `transBySelector和transDesc函数`延迟执行时间 + 1. 更新: 忽略规则, 词条等 + + #### v1.8.4 (2023-08-08) + + 1. 修复: `Itemprop`过滤规则, 依然使用正则方式 + 1. 修复: `tooltipped`样式提示, 依然使用正则方式 + + #### v1.8.3 (2023-08-07) + + 1. 梳理、优化脚本 + 1. 更新: 忽略规则, 大量词条等 + + #### v1.8.2 (2023-05-15) + + 1. `greasyfork 托管`源切换到`按页面精细化词条模式` + 1. 调整词库格式 + 1. 功能加强: 优化`元素筛选器`翻译逻辑 + 1. 更新: 忽略规则, 大量词条等 + + #### v1.8.1 (2023-01-22) + + 1. 修复: #8 与 dark reader 扩展发生冲突,导致时间显示出现问题 + 1. `GitHub`源开始切换到`按页面精细化词条模式(开发版)`, 词库未完全迁移适配 + 1. 停止`greasyfork`源词库文件的同步更新 + + #### v1.8.0 (2023-01-18) + + 1. 删除: `TURBO-FRAME`框架处理代码. Github 已调整新动态加载模式, 直接检测`url`的变化就能获取对应的`page`信息 + 1. 新增: 支持时间元素的`Shadow DOM`翻译, 并监听变化 + 1. 新增: 启用并更新`时间元素翻译`专项正则词条 + 1. 新增: 仅当`page`有效才翻译页面 + 1. 修复: 原`简介翻译`引擎`GitHub中文社区`失效, 改为`讯飞`引擎(测试) + 1. 修复: 追加公共正则重复迭代的问题 + 1. 修复: 正则标记变量`RegExp`与构造函数`new RegExp`冲突 + 1. 更新: 忽略规则, 词条等 + + 预告, 下次将细化`page`匹配规则, 导致词库文件结构大调整, 词库文件会适当变大, 页面正则更精细效率会提升 + + #### v1.7.9 (2022-07-17) + + GitHub 的 ajax 载入方式逐步从 [defunkt/jquery-pjax](https://github.com/defunkt/jquery-pjax) 切换到 [hotwired/turbo](turbo.hotwired.dev), 导致已有的动态监测方式逐步失效 + + 目前, 通过以下修复: + + 1. 新增 `BODY` 元素新增监视 + 1. 解析 `TURBO-FRAME` 框架, 获取对应的 `page` + 1. 修复 github 新动态加载模式, 导致`翻译描述`返回值无法插入 + 1. 修复 github 新动态加载模式, 导致`chrome`浏览器自带翻译功能卡死页面 + + 其他更新: + + 1. 修复`rePagePath`,`rePagePathRepo`,`rePagePathOrg`匹配规则,限制路径匹配层次,排除干扰 + 1. 直接使用网页URL`document.URL`变化触发`标题翻译`和`JS 筛选器`翻译 + 1. 修复`关闭正则`无法生效, 需要刷新页面才生效 + 1. 日常更新词库和忽略规则 + 1. 更新`JS 筛选器`规则 + + #### v1.7.8 (2022-06-29) + + 1. 紧急修复: GitHub 变更了`document.body`和`title`更新机制, 导致原有的`监测更新`规则部分失效, 目前使用`document.documentElement`监视整个页面 DOM 的变更 + 1. 跳过``标签 + 1. `标题翻译`和`JS 筛选器`翻译, 依据 URL变化更新 + + #### v1.7.7 (2022-06-26) + + 1. 新增`时间元素翻译`功能 + 1. 重写`页面标题翻译`函数 + 1. 梳理`遍历节点`函数逻辑 + 1. 优化`transPage`函数,默认翻译公共部分 + 1. 调整`getPage`函数, 使`ClassName匹配规则`优先 + 1. 优化`translate`函数, 跳过`不存在英文字母和符号,.`, 保留首尾空白部分等 + 1. 部分函数重命名,使用`es6`新语法 + 1. 日常更新词库和忽略规则,修复一个`JS 选择器规则` + + #### v1.7.6 (2022-05-12) + + 1. 日常更新词库和忽略规则 + 1. 添加手动开启/禁用正则翻译,添加切换菜单 + 1. 优化翻译文本函数:避免已翻译词汇二次匹配,提高效率;局部翻译优先于全局 + +
+ back_to_top: |- +
+ + [![][back-to-top]](#readme-top) + +
+ +# ── 待办事项 ── +todo: + heading: + CN: 📌 待办事项 + TW: 📌 待辦事項 + items: + CN: |- + 1. 添加 GitHub 专用名词解释 + 1. 整理 [Git](https://git-scm.com/) & [GitHub](https://github.com/) 学习资料 + 1. 完善文档翻译,需大家 PR 共同翻译 + TW: |- + 1. 添加 GitHub 專用名詞解釋 + 1. 整理 [Git](https://git-scm.com/) & [GitHub](https://github.com/) 學習資料 + 1. 完善文檔翻譯,需大家 PR 共同翻譯 + +# ── 参与贡献 ── +contribute: + heading: + CN: 🤝 参与贡献 + TW: 🤝 參與貢獻 + text: + CN: 请参阅《[贡献指南](CONTRIBUTING.md)》。 + TW: 請參閱 [貢獻指南](CONTRIBUTING_zh-TW.md)。 + +# ── 效果预览 ── +preview: + heading: + CN: 🖼️ 效果预览 + TW: 🖼️ 效果預覽 + images: |- + + + + + + + + + + + +# ── 特别鸣谢 ── +thanks: + heading: + CN: 🙏 特别鸣谢 + TW: 🙏 特別鳴謝 + team: + heading: + CN: 核心团队 + TW: 核心團隊 + items: + CN: |- + - [maboloshi](https://github.com/maboloshi) - 项目作者 + - [wyc-26](https://github.com/wyc-26),[陈生杂物房](https://github.com/TC999) - 项目协作者 + - [52cik](https://github.com/52cik) - 项目原作者 + TW: |- + - [maboloshi](https://github.com/maboloshi) - 項目作者 + - [wyc-26](https://github.com/wyc-26),[陳生雜物房](https://github.com/TC999) - 項目協作者 + - [52cik](https://github.com/52cik) - 項目原作者 + contributors: + heading: + CN: 贡献者墙 + TW: 貢獻者牆 + intro: + CN: 一如既往,感谢我们出色的贡献者❤️! + TW: 一如既往,感謝我們出色的貢獻者❤️! + # 由 update_contributors_images.yml 自动更新(CN/TW 共享同一份列表) + list: |- + + 沙漠之子 + 楼教主 + 陈生杂物房 + wyc-26 + 其智乃反不能及 + Lu Yifei + Paper Moon + cat-kun + 大叶子 + Mr.Baoboer + Kise Platinyl + Pecasha + poney + 人民的勤务员 + Sebastion + PtJade Ceramic + Oliver Lin + AlanWang + 苓𥤚 + 益生君 + 小莫 + 学渣驹 + 叹号大帝 + 前端小武 + wang4yu6peng13 + pangshitong + dayday + create new ██████╗  ██╔══██╗ ██████╔╝ ██╔══██╗ ██████╔╝ ╚═════╝    ██╗    ██╗   ██║    ██║   ██║    ██║   ██║    ██║   ╚█████╔╝    ╚═════╝  ███████╗ ██╔════╝  ██║████═╗  ██║    ██ ║ ╚██████╔╝   ╚══════╝ + Shuwn Hsu + NyA!K0 + MaydayV + KS-OTO + InfinityLoop + Imgbot + Heavenless + Flint Scophire + neveler + + note: + CN: "> 贡献者列表,由 [GitHub Action][update-contributors-images] 自动生成" + TW: "> 貢獻者列表,由 [GitHub Action][update-contributors-images] 自動生成" + back_to_top: |- +
+ + [![][back-to-top]](#readme-top) + +
+ +# ── 项目统计 ── +stats: + heading: + CN: 📈 项目统计 + TW: 📈 項目統計 + content: |- + + + + + Star History Chart + + + + ![Alt](https://repobeats.axiom.co/api/embed/ae4c378f0e6ec317654ec5c4e8b01218c734cd53.svg "Repobeats analytics image") + back_to_top: |- +
+ + [![][back-to-top]](#readme-top) + +
+ +# ── 欢迎打赏 ── +donate: + heading: + CN: 🎁 欢迎打赏 + TW: 🎁 歡迎打賞 + content: + CN: |- + [赞赏列表](https://github.com/maboloshi/maboloshi/issues/1) + | 微信赞赏 | 支付宝赞赏 | + | :--------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------: | + | WeChat QRcode
☕喝点咖啡继续干☕ | AliPay QRcode
🌶️来包辣条吧~🍪 | + TW: |- + [讚賞列表](https://github.com/maboloshi/maboloshi/issues/1) + | 微信讚賞 | 支付寶讚賞 | + | :--------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------: | + | WeChat QRcode
☕喝點咖啡繼續幹☕ | AliPay QRcode
🌶️來包辣條吧~🍪 | + +# ── 链接引用定义(共享) ── +links: |- + + + [back-to-top]: https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square + [github-project-link]: https://github.com/maboloshi/github-chinese "GitHub 中文化插件" + [github-issues-link]: https://github.com/maboloshi/github-chinese/issues "议题" + [github-issues-shield]: https://img.shields.io/github/issues/maboloshi/github-chinese?style=flat-square&logo=github&label=Issue + [github-stars-link]: https://github.com/maboloshi/github-chinese/stargazers "星标" + [github-stars-shield]: https://img.shields.io/github/stars/maboloshi/github-chinese?style=flat-square&logo=github&label=Star + [github-forks-link]: https://github.com/maboloshi/github-chinese/network "复刻" + [github-forks-shield]: https://img.shields.io/github/forks/maboloshi/github-chinese?style=flat-square&logo=github&label=Fork + [github-license-link]: https://opensource.org/licenses/GPL-3.0 "许可证" + [github-license-shield]: https://img.shields.io/github/license/maboloshi/github-chinese?style=flat-square&logo=github&label=License + [greasyFork-link]: https://greasyfork.org/scripts/435208 "GreasyFork 源 - GitHub 中文化插件" + [greasyFork-shield]: https://img.shields.io/greasyfork/dt/435208?style=flat-square&logo=GreasyFork&label=GreasyFork%20Installs + [Tampermonkey]: http://tampermonkey.net/ "篡改猴" + [Violentmonkey]: https://violentmonkey.github.io/ "暴力猴" + [Macaque]: https://macaque.app/ "猕猴" + [Stay]: https://apps.apple.com/cn/app/stay-for-safari-%E6%B5%8F%E8%A7%88%E5%99%A8%E4%BC%B4%E4%BE%A3/id1591620171 "Stay" + [main.user.js]: https://github.com/maboloshi/github-chinese/raw/gh-pages/main.user.js "GitHub 中文化插件 - GitHub 源" + [main(nju.edu).user.js]:https://mirror.nju.edu.cn/github-chinese/main(nju.edu).user.js "GitHub 中文化插件 - 南大镜像源" + [main(greasyfork).user.js]: https://greasyfork.org/scripts/435208-github-%E4%B8%AD%E6%96%87%E5%8C%96%E6%8F%92%E4%BB%B6/code/GitHub%20%E4%B8%AD%E6%96%87%E5%8C%96%E6%8F%92%E4%BB%B6.user.js "GitHub 中文化插件 - GreasyFork 源" + [update-contributors-images]: https://github.com/maboloshi/github-chinese/blob/gh-pages/.github/workflows/update_contributors_images.yml + [Integrated Browser Extensions]: https://marketplace.visualstudio.com/items?itemName=boylett.integrated-browser-extensions "Integrated Browser Extensions" diff --git "a/script/multilingual-docs/bug-\346\217\220\344\272\244.yml" "b/script/multilingual-docs/bug-\346\217\220\344\272\244.yml" new file mode 100644 index 000000000..3f51fdf8b --- /dev/null +++ "b/script/multilingual-docs/bug-\346\217\220\344\272\244.yml" @@ -0,0 +1,178 @@ +# 多语言议题模板 —— 唯一维护来源 +# 由 manage_templates.py 校验并生成 CN/TW 模板。 +# +# 规则: +# - 纯字符串 → CN/TW 共享该值 +# - CN: "简体" +# - TW: "繁體" → 分语言翻译 +# - 结构字段(type, id, validations)不翻译,保持原样 + +name: + CN: Bug 提交(简体中文) + TW: Bug 提交(繁體中文) +description: 提交 BUG +labels: bug + +body: +- type: markdown + attributes: + value: + CN: '### 欢迎!' + TW: '### 歡迎!' +- type: markdown + attributes: + value: + CN: | + 感谢您提交议题!请补充以下内容,以便我们能更好地协助您。 + + 提交议题前确保您已阅读[常见问题(FAQ)](https://github.com/maboloshi/github-chinese/issues/493)。 + TW: | + 感謝您提交議題!請補充以下內容,以便我們能更好地協助您。 + + 提交議題前確保您已閱讀[常見問題(FAQ)](https://github.com/maboloshi/github-chinese/issues/493)。 +- type: textarea + id: description + attributes: + label: + CN: 问题/建议 + TW: 問題/建議 + description: + CN: 请描述你遇到的问题/提出的建议。 + TW: 請描述你遇到的問題/提出的建議。 + validations: + required: true +- type: textarea + id: steps + attributes: + label: + CN: 步骤 + TW: 步驟 + description: + CN: 请逐步描述你遇到的问题,并带上测试链接(如有)。 + TW: 請逐步描述你遇到的問題,並帶上測試連結(如有)。 + validations: + required: true +- type: textarea + id: expected + attributes: + label: + CN: 预期 + TW: 預期 + description: + CN: 请描述你对本插件行为的预期。 + TW: 請描述你對本插件行為的預期。 + validations: + required: true +- type: textarea + id: real + attributes: + label: + CN: 实际 + TW: 實際 + description: + CN: 请描述本插件的实际行为。 + TW: 請描述本插件的實際行為。 + validations: + required: true +- type: textarea + id: evidence + attributes: + label: + CN: 附件 + TW: 附件 + description: + CN: 请提供相关截图或附件(如有)。 + TW: 請提供相關截圖或附件(如有)。 + validations: + required: false +- type: dropdown + id: browser-name + attributes: + label: + CN: 浏览器名称 + TW: 瀏覽器名稱 + description: + CN: 请选择运行本插件的浏览器的名称。 + TW: 請選擇運行本插件的瀏覽器的名稱。 + options: + - Microsoft Edge + - Google Chrome + - Others + validations: + required: true +- type: input + id: browser-version + attributes: + label: + CN: 浏览器版本 + TW: 瀏覽器版本 + description: + CN: | + 请填入运行本插件的浏览器的版本。 + + [Microsoft Edge](https://support.microsoft.com/zh-cn/microsoft-edge/c726bee8-c42e-e472-e954-4cf5123497eb) · + [Google Chrome](chrome://settings/help) + TW: | + 請填入運行本插件的瀏覽器的版本。 + + [Microsoft Edge](https://support.microsoft.com/zh-cn/microsoft-edge/c726bee8-c42e-e472-e954-4cf5123497eb) · + [Google Chrome](chrome://settings/help) + placeholder: + CN: 版本 146.0.3856.62 (正式版本) (arm64) + TW: 版本 146.0.3856.62 (正式組建) (arm64) + validations: + required: true +- type: dropdown + id: script-manager-name + attributes: + label: + CN: 脚本管理器名称 + TW: 腳本管理器名稱 + description: + CN: 请选择管理本插件的脚本管理器的名称。 + TW: 請選擇管理本插件的腳本管理器的名稱。 + options: + - 篡改猴(Tampermonkey) + - Others + validations: + required: true +- type: input + id: script-manager-version + attributes: + label: + CN: 脚本管理器版本 + TW: 腳本管理器版本 + description: + CN: | + 请填入管理本插件的脚本管理器的版本。 + + [Microsoft Edge 扩展](https://support.microsoft.com/zh-cn/topic/a3ae1ebb-8e7f-49df-a5f8-8c3f56c8078b) + TW: | + 請填入管理本插件的腳本管理器的版本。 + + [Microsoft Edge 擴展](https://support.microsoft.com/zh-cn/topic/a3ae1ebb-8e7f-49df-a5f8-8c3f56c8078b) + placeholder: "5.4.1" + validations: + required: true +- type: input + id: plugin-version + attributes: + label: + CN: 插件版本 + TW: 外掛版本 + description: + CN: | + 请填入 GitHub 中文化插件的版本。 + + 见本插件源码中 `@version` 的值(不再接受 1.9.2 版本反馈)。 + + [Microsoft Edge](extension://iikmkjmpaadaobahmlepeloendndfphd/options.html) + TW: | + 請填入 GitHub 中文化外掛的版本。 + + 見本外掛原始碼中 `@version` 的值(不再接受 1.9.2 版本回饋)。 + + [Microsoft Edge](extension://iikmkjmpaadaobahmlepeloendndfphd/options.html) + placeholder: "1.9.3" + validations: + required: true diff --git a/script/multilingual-docs/vscode-extension-README.md.j2 b/script/multilingual-docs/vscode-extension-README.md.j2 new file mode 100644 index 000000000..3ff7773bc --- /dev/null +++ b/script/multilingual-docs/vscode-extension-README.md.j2 @@ -0,0 +1,24 @@ +{# 通用递归渲染:结构与层级完全由 YAML 数据(键顺序 + heading 嵌套)推断, + 模板本身不硬编码任何块名/顺序/层级。#} +{%- macro render(node, depth=0) -%} +{%- set ns = namespace(lines=[]) -%} +{%- for key, value in node.items() -%} +{%- if value is mapping and (value.keys() | list | first) == 'heading' -%} +{%- set _ = ns.lines.append('#' * (depth + 2) + ' ' + value['heading']) -%} +{%- set _ = ns.lines.append('') -%} +{%- set body = namespace(d={}) -%} +{%- for k2, v2 in value.items() -%} +{%- if k2 != 'heading' -%}{%- set _ = body.d.update({k2: v2}) -%}{%- endif -%} +{%- endfor -%} +{%- if body.d -%} +{%- set _ = ns.lines.append(render(body.d, depth + 1) | trim) -%} +{%- set _ = ns.lines.append('') -%} +{%- endif -%} +{%- elif value is string -%} +{%- set _ = ns.lines.append(('# ' + value) if key == 'title' else value) -%} +{%- set _ = ns.lines.append('') -%} +{%- endif -%} +{%- endfor -%} +{{ ns.lines | join('\n') -}} +{%- endmacro %} +{{- render(resolved) -}} diff --git a/script/multilingual-docs/vscode-extension-README.yml b/script/multilingual-docs/vscode-extension-README.yml new file mode 100644 index 000000000..c7700c51e --- /dev/null +++ b/script/multilingual-docs/vscode-extension-README.yml @@ -0,0 +1,129 @@ +# VS Code 扩展自述 —— 唯一维护来源 +# 由 manage_templates.py 校验并生成 CN/TW 扩展自述。 +# TW 为 opencc s2tw 自动转换草案,供人工校对。 + +top_align_begin:
+ +title: + CN: GitHub 中文化 (VS Code 扩展) + TW: GitHub 中文化 (VS Code 擴展) + +slogan: + CN: 一键安装 GitHub 中文化脚本到 VS Code 集成浏览器。 + TW: 一鍵安裝 GitHub 中文化腳本到 VS Code 集成瀏覽器。 + +lang_links: + CN: "**简体中文** · [繁體中文](./README_zh-TW.md)" + TW: "[简体中文](./README.md) · **繁體中文**" + +badge: |- + + + [![license GPL-3.0](https://img.shields.io/github/license/maboloshi/github-chinese?style=flat-square&label=License)](https://opensource.org/licenses/GPL-3.0) + +top_align_end:
+ +prereq: + heading: + CN: 前提 + TW: 前提 + install_dep: + heading: + CN: 安装依赖扩展 + TW: 安裝依賴擴展 + text: + CN: | + 需要 [Integrated Browser Extensions](https://marketplace.visualstudio.com/items?itemName=boylett.integrated-browser-extensions)。 + + > [!WARNING] + > 该依赖扩展的 GitHub 源码仓库已被作者删除(404),市场列表仍存在但扩展不再维护。功能在当前版本中正常可用,但未来可能因 VS Code 更新而失效。 + + > [!NOTE] + > 本扩展尚未上架 [VS Code 市场](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_find-and-install-an-extension),需通过[源码构建](#从本仓库源码构建)或下载 VSIX 安装。上架后从市场安装时会自动安装 Integrated Browser Extensions。 + TW: | + 需要 [Integrated Browser Extensions](https://marketplace.visualstudio.com/items?itemName=boylett.integrated-browser-extensions)。 + + > [!WARNING] + > 該依賴擴展的 GitHub 源碼倉庫已被作者刪除(404),市場列表仍存在但擴展不再維護。功能在當前版本中正常可用,但未來可能因 VS Code 更新而失效。 + + > [!NOTE] + > 本擴展尚未上架 [VS Code 市場](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_find-and-install-an-extension),需通過[源碼構建](#從本倉庫源碼構建)或下載 VSIX 安裝。上架後從市場安裝時會自動安裝 Integrated Browser Extensions。 + launch_args: + heading: + CN: 添加启动参数 + TW: 添加啟動參數 + text: + CN: | + VS Code 必须带 `--enable-proposed-api boylett.integrated-browser-extensions` 参数启动。 + +
+ 带参数启动 VS Code 的方式 + + - 打开[运行对话框](https://learn.microsoft.com/windows/advanced-settings/modern-run),录入: + ```cmd + "%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe" --enable-proposed-api boylett.integrated-browser-extensions + ``` + - 或修改[“开始”菜单](https://www.microsoft.com/zh-cn/windows/tips/start-menu)的 VS Code 快捷方式,在 `目标` 字段末尾追加 [COMMAND_LINE_ARGUMENTS](https://learn.microsoft.com/openspecs/windows_protocols/ms-shllink/17b69472-0f34-4bcf-b290-eccdb8de224b): + ```cmd + --enable-proposed-api boylett.integrated-browser-extensions + ``` + 然后从“开始”菜单启动 + +
+ TW: | + VS Code 必須帶 `--enable-proposed-api boylett.integrated-browser-extensions` 參數啟動。 + +
+ 帶參數啟動 VS Code 的方式 + + - 打開[運行對話框](https://learn.microsoft.com/windows/advanced-settings/modern-run),錄入: + ```cmd + "%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe" --enable-proposed-api boylett.integrated-browser-extensions + ``` + - 或修改[“開始”菜單](https://www.microsoft.com/zh-cn/windows/tips/start-menu)的 VS Code 快捷方式,在 `目標` 字段末尾追加 [COMMAND_LINE_ARGUMENTS](https://learn.microsoft.com/openspecs/windows_protocols/ms-shllink/17b69472-0f34-4bcf-b290-eccdb8de224b): + ```cmd + --enable-proposed-api boylett.integrated-browser-extensions + ``` + 然後從“開始”菜單啟動 + +
+ +build: + heading: + CN: 从本仓库源码构建 + TW: 從本倉庫源碼構建 + steps: + CN: | + 1. [克隆仓库](https://docs.github.com/zh/repositories/creating-and-managing-repositories/cloning-a-repository) + 1. [在 VS Code 中打开该文件夹](https://code.visualstudio.com/docs/editor/workspaces#_folder-projects) + 1. [打开终端](https://code.visualstudio.com/docs/terminal/getting-started#_run-your-first-command-in-the-terminal),执行: + ```powershell + cd vscode-extension + npm install + npx @vscode/vsce package + ``` + 1. [从 VSIX 安装](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_install-from-a-vsix) + + > [!TIP] + > 推荐从[发行版](https://github.com/maboloshi/github-chinese/releases)直接下载 `.vsix`(如有)。 + TW: | + 1. [克隆倉庫](https://docs.github.com/zh/repositories/creating-and-managing-repositories/cloning-a-repository) + 1. [在 VS Code 中打開該文件夾](https://code.visualstudio.com/docs/editor/workspaces#_folder-projects) + 1. [打開終端](https://code.visualstudio.com/docs/terminal/getting-started#_run-your-first-command-in-the-terminal),執行: + ```powershell + cd vscode-extension + npm install + npx @vscode/vsce package + ``` + 1. [從 VSIX 安裝](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_install-from-a-vsix) + + > [!TIP] + > 推薦從[發行版](https://github.com/maboloshi/github-chinese/releases)直接下載 `.vsix`(如有)。 + +debug: + heading: + CN: 调试 + TW: 調試 + text: + CN: "[打开扩展开发宿主窗口](https://code.visualstudio.com/api/get-started/your-first-extension#debugging-the-extension)。" + TW: "[打開擴展開發宿主窗口](https://code.visualstudio.com/api/get-started/your-first-extension#debugging-the-extension)。" diff --git a/script/update_contributors.py b/script/update_contributors.py new file mode 100644 index 000000000..5bfaf7e74 --- /dev/null +++ b/script/update_contributors.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +"""更新 README.yml 的贡献者墙(thanks.contributors.list 共享块)。 + +由 .github/workflows/update_contributors_images.yml 调用。 +用法:printf '%s' "$HTML_LIST" | python script/update_contributors.py + +HTML_LIST 由 jaywcjlove/github-action-contributors 输出(不含 AUTO_GENERATED 标记), +本脚本将其嵌入 标记之间写入 YAML 源。 +""" +import sys +from pathlib import Path + +README_YML = Path("script/multilingual-docs/README.yml") +MARKER = " list: |-" + +# Windows 本地调试时强制 UTF-8,避免罕见汉字在 GBK 管道下解码出错 +for stream in (sys.stdin, sys.stdout): + if hasattr(stream, "reconfigure"): + stream.reconfigure(encoding="utf-8") # type: ignore[union-attr] + +html = sys.stdin.read().strip().replace("\\n", "\n") +if not html: + print("⚠️ 空 HTML 列表,跳过", file=sys.stderr) + sys.exit(1) + +lines = README_YML.read_text(encoding="utf-8").splitlines() + +try: + start = next(i for i, l in enumerate(lines) if l == MARKER) +except StopIteration: + print("❌ 未找到贡献者墙 list 字段", file=sys.stderr) + sys.exit(1) + +content_indent = " " * (len(MARKER) - len(MARKER.lstrip()) + 2) # 6 空格 + +new_lines = lines[: start + 1] +new_lines.append(content_indent + "") +for line in html.splitlines(): + new_lines.append(content_indent + line if line else "") +new_lines.append(content_indent + "") + +# 跳过旧 list 块内容(缩进 >= 6 的空格开头,或空行) +i = start + 1 +while i < len(lines) and (lines[i].startswith(content_indent) or lines[i] == ""): + i += 1 +new_lines.extend(lines[i:]) + +data = "\n".join(new_lines) + "\n" +# 写前先验证可编码,避免异常导致目标文件被截断为空 +try: + data.encode("utf-8") +except UnicodeEncodeError as exc: + print(f"❌ 输出含无法编码的字符,未写入:{exc}", file=sys.stderr) + sys.exit(1) + +README_YML.write_text(data, encoding="utf-8") +print(f"✅ 已更新 {README_YML}") diff --git a/test/test_pre_commit_hook.sh b/test/test_pre_commit_hook.sh new file mode 100644 index 000000000..0a804a435 --- /dev/null +++ b/test/test_pre_commit_hook.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# 测试 .githooks/pre-commit 钩子行为(模型 B:生成文件不入库,由 CI 自动生成) +# +# 用法:bash test/test_pre_commit_hook.sh +# 前置条件:`python` 可执行且已安装依赖(pyyaml、Jinja2、opencc-python-reimplemented) +# +# 场景: +# A. 工作区生成文件与源文件渲染不一致(手动修改)→ 应阻止提交并打印差异 +# B. 修改源文件且工作区生成文件已同步 → 应提交成功;生成文件不入库 +# C. 无关改动 → 应直接放行 +set -euo pipefail + +# 非交互环境:钩子检测到不一致时跳过 Y/N 询问,默认视为 N(取消提交) +export GIT_HOOK_NONINTERACTIVE=1 + +ROOT="$(cd "$(dirname "$0")/.." && pwd)" +TMP="$(mktemp -d)" +trap 'rm -rf "$TMP" 2>/dev/null || true' EXIT + +cd "$TMP" +git init -q +git config user.name "test" +git config user.email "test@example.com" +git config core.hooksPath ".githooks" + +# 复制钩子、源文件与 .gitignore(生成文件不入库) +mkdir -p .githooks script/multilingual-docs .github/ISSUE_TEMPLATE vscode-extension +cp "$ROOT/.githooks/pre-commit" .githooks/pre-commit +chmod +x .githooks/pre-commit +cp "$ROOT/.gitignore" .gitignore +cp "$ROOT/pyproject.toml" pyproject.toml +cp "$ROOT/script/manage_templates.py" script/manage_templates.py +cp "$ROOT/script/multilingual-docs/"./* script/multilingual-docs/ + +# 生成到工作区;baseline 只提交源文件(生成文件被 gitignore,不入库) +python script/manage_templates.py >/dev/null +git add -A +git commit -q -m "baseline" + +fail() { echo "❌ FAIL: $1"; exit 1; } + +# ── 断言:改源文件提交,若工作区生成文件与源文件渲染不一致 → 应阻止并打印差异 ── +assert_blocked() { + local desc="$1" + git add script/multilingual-docs/ + local before; before="$(git rev-parse HEAD)" + local output; output="$(git commit -m "source change" 2>&1 || true)" + [ "$(git rev-parse HEAD)" = "$before" ] || fail "场景A($desc):不一致未被阻止" + echo "$output" | grep -q "不一致" || fail "场景A($desc):未打印不一致提示" + echo "$output" | grep -q "请通过源文件修改" || fail "场景A($desc):未提示通过源文件修改" + echo "$output" | grep -q "重新生成" || fail "场景A($desc):未提示重新生成选项" + git reset -q --hard + echo "✅ 场景A($desc):被阻止并打印差异" +} + +# ── 场景 A:改源文件并同步生成后,再手动修改 README.md → 应阻止 ── +sed -i 's/CN: 贡献指南/CN: 贡献指南钩子测试/; s/TW: 貢獻指南/TW: 貢獻指南鉤子測試/' \ + script/multilingual-docs/CONTRIBUTING.yml +python script/manage_templates.py >/dev/null +echo "" >> README.md +assert_blocked "手动修改 README.md" + +# 恢复:重置源文件改动 + 重新生成(README 回到 baseline 渲染) +git reset -q --hard +python script/manage_templates.py >/dev/null + +# ── 场景 B:改源文件 + 生成同步 → 应提交成功,生成文件不入库 ── +sed -i 's/CN: 贡献指南/CN: 贡献指南钩子测试/; s/TW: 貢獻指南/TW: 貢獻指南鉤子測試/' \ + script/multilingual-docs/CONTRIBUTING.yml +python script/manage_templates.py >/dev/null +git add script/multilingual-docs/ +git commit -q -m "source change" || fail "场景B:源文件变更被阻止" +git show --stat HEAD | grep -q "CONTRIBUTING.md" && fail "场景B:生成文件不应入库" +git show --stat HEAD | grep -q "README.md" && fail "场景B:生成文件不应入库" +git show --stat HEAD | grep -q "CONTRIBUTING.yml" || fail "场景B:源文件未提交" +[ -z "$(git status --short)" ] || fail "场景B:提交后工作区不干净" +echo "✅ 场景B:源文件提交成功,生成文件不入库" + +# ── 场景 C:无关改动 → 应直接放行 ── +echo "unrelated" > unrelated.txt +git add unrelated.txt +git commit -q -m "unrelated" || fail "场景C:无关改动被阻止" +echo "✅ 场景C:无关改动直接放行" + +echo "" +echo "🎉 全部钩子测试通过" diff --git a/vscode-extension/README.md b/vscode-extension/README.md deleted file mode 100644 index 77e2d92da..000000000 --- a/vscode-extension/README.md +++ /dev/null @@ -1,55 +0,0 @@ -# GitHub 中文化 (VS Code 扩展) - -[![license GPL-3.0](https://img.shields.io/github/license/maboloshi/github-chinese?style=flat-square&label=License)](https://opensource.org/licenses/GPL-3.0) - -一键安装 GitHub 中文化脚本到 VS Code 集成浏览器。 - -## 前提 - -### 安装依赖扩展 - -需要 [Integrated Browser Extensions](https://marketplace.visualstudio.com/items?itemName=boylett.integrated-browser-extensions)。 - -> [!WARNING] -> 该依赖扩展的 GitHub 源码仓库已被作者删除(404),市场列表仍存在但扩展不再维护。功能在当前版本中正常可用,但未来可能因 VS Code 更新而失效。 - -> [!NOTE] -> 本扩展尚未上架 [VS Code 市场](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_find-and-install-an-extension),需通过[源码构建](#从本仓库源码构建)或下载 VSIX 安装。上架后从市场安装时会自动安装 Integrated Browser Extensions。 - -### 添加启动参数 - -VS Code 必须带 `--enable-proposed-api boylett.integrated-browser-extensions` 参数启动。 - -
-带参数启动 VS Code 的方式 - -- 打开[运行对话框](https://learn.microsoft.com/windows/advanced-settings/modern-run),录入: - ```cmd - "%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe" --enable-proposed-api boylett.integrated-browser-extensions - ``` -- 或修改[“开始”菜单](https://www.microsoft.com/zh-cn/windows/tips/start-menu)的 VS Code 快捷方式,在 `目标` 字段末尾追加 [COMMAND_LINE_ARGUMENTS](https://learn.microsoft.com/openspecs/windows_protocols/ms-shllink/17b69472-0f34-4bcf-b290-eccdb8de224b): - ```cmd - --enable-proposed-api boylett.integrated-browser-extensions - ``` - 然后从“开始”菜单启动 - -
- -## 从本仓库源码构建 - -1. [克隆仓库](https://docs.github.com/zh/repositories/creating-and-managing-repositories/cloning-a-repository) -1. [在 VS Code 中打开该文件夹](https://code.visualstudio.com/docs/editor/workspaces#_folder-projects) -1. [打开终端](https://code.visualstudio.com/docs/terminal/getting-started#_run-your-first-command-in-the-terminal),执行: - ```powershell - cd vscode-extension - npm install - npx @vscode/vsce package - ``` -1. [从 VSIX 安装](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_install-from-a-vsix) - -> [!TIP] -> 推荐从[发行版](https://github.com/maboloshi/github-chinese/releases)直接下载 `.vsix`(如有)。 - -## 调试 - -[打开扩展开发宿主窗口](https://code.visualstudio.com/api/get-started/your-first-extension#debugging-the-extension)。