仓库页在 Turbo 软导航后整页无法翻译:isRepository 依赖的 analytics-location 是 transient meta

Đang mở
#809 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
44/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
github, javascript

Hướng nghiên cứu

Start in main.user.js at detectPageType() and inspect how it uses analytics-location and pathname to identify repository pages. Reproduce the reported Turbo soft-navigation failure and check the proposed fallback against the reserved paths listed in the issue. Done means repository pages translate after soft navigation without misclassifying those reserved routes; the issue also reports vocabulary gaps and character-data updates to investigate.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug
问题/建议

环境

  • 脚本版本:1.9.4.4-2026-09-27(GitHub 源 / 南大镜像源均复现)
  • Tampermonkey 5.x / Edge 142 / Windows 11

现象

从站内点击链接进入仓库页(/<owner>/<repo>)时,页面完全不被翻译,
Console 输出:

[i18n] 路径未匹配任何页面规则
【Debug】首次载入触发, 页面类型为 undefined

直接在地址栏输入 URL 或刷新页面则一切正常。

根因

detectPageType() 中仓库页判定完全依赖 analytics meta:

const isRepository = /\/<user-name>\/<repo-name>/.test(metaLocation);
而该 meta 带 Turbo 临时标记:
<meta name="analytics-location" content="/<user-name>/<repo-name>" data-turbo-transient="true">
data-turbo-transient 的元素在 Turbo 软导航(pjax/turbo:load)时会被移除或延迟更新。
脚本在 URL 变化回调中调用 detectPageType() 时 meta 尚未恢复 → metaLocation === ''
→ isRepository === false → pathname /owner/repo 又不被 rePagePath 匹配
→ pageType === false → State.pageConfig = null → 整页放弃翻译。
这解释了"直达/刷新正常、站内点击不正常"的间歇性表现。
修复建议
isRepository 增加 URL 结构兜底:两段式路径(排除保留字首段)也判定为仓库页,
不再单独依赖该 meta。已实测 16 个典型 URL(仓库/设置/组织/主题/探索/通知/Copilot 等)无误判:
--- a/main.user.js
+++ b/main.user.js
@@ -366,7 +366,15 @@
         const isSession = document.body.classList.contains("session-authentication");
         const isHomepage = pathname === '/' && site === 'github';
         const isProfile = document.body.classList.contains("page-profile") || metaLocation === '/<user-name>';
-        const isRepository = /\/<user-name>\/<repo-name>/.test(metaLocation);
+        // 兜底:analytics-location 是 data-turbo-transient 临时 meta,Turbo 软导航时
+        // 可能被移除或更新延迟,导致仓库页被判为未知页面而整页放弃翻译
+        // (症状:站内点击进入 /owner/repo 时 Console 输出"路径未匹配任何页面规则")。
+        // 增加两级 URL 结构兜底:两段式路径(排除保留字首段)也视为仓库页。
+        const reservedFirstSegment = /^\/(?:home|dashboard|feed|copilot|spark|signup|account_verifications|login|logout|sessions?|password_reset|orgs|organizations|explore|topics|notifications|watching|stars|issues|pulls|repos|search|discussions|gist|sponsors|marketplace|apps|codespaces|developer|features|status|education|sitemap|mcp|settings|account|new|redeem|trending|collections|showcases|about|pricing|security|enterprise|customer-stories|site|support|learn|events|tools|edu|campus|git|contact|users|installations|billing|plans)\//i;
+        const isRepository = /\/<user-name>\/<repo-name>/.test(metaLocation)
+            || (site === 'github'
+                && !reservedFirstSegment.test(pathname)
+                && /^\/[^\/@?#]+\/[^\/@?#]+(?:\/|$)/.test(pathname));
完整 patch 文件(含 GlobalNav 空闲条件的重试上限兜底)见附件。
附带反馈:新版 UI 词条缺口(v1.9.4.4 词库)
以下文案在新版仓库页/设置页出现且词库暂未覆盖,实测未命中:
- Latest commit、Folders and files、Repository navigation、Repository files navigation、Open more actions menu
- Cloud agent、Policy insights、Private repository、Report abuse、Global navigation menu
- 两步验证 / 离开仓库对话框的整句提示
另外建议 characterDataPage 白名单加入 repository、repository/tree:
新版仓库侧边栏为骨架屏注水(prc-SkeletonText),水合会以 characterData 突变
覆盖已翻译文本,当前白名单不含仓库页导致英文残留。
复现与定位过程详见控制台日志:【Debug】首次载入触发, 页面类型为 undefined。

### 步骤

## 现象

从站内点击链接进入仓库页(`/<owner>/<repo>`)时,页面完全不被翻译,
Console 输出:

[i18n] 路径未匹配任何页面规则
【Debug】首次载入触发, 页面类型为 undefined

直接在地址栏输入 URL 或刷新页面则一切正常。

### 预期

本应全部翻译

### 实际

很多未翻译

### 附件

_No response_

### 浏览器名称

Microsoft Edge

### 浏览器版本

146.0.3856

### 脚本管理器名称

篡改猴(Tampermonkey)

### 脚本管理器版本

5.4.1

### 插件版本

1.9.3
Ngôn ngữ chính
JavaScript
Star
35.1k
Fork
2k
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
9

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của maboloshi/github-chinese

Tất cả issue của maboloshi/github-chinese

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.