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

未关闭
#809 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
44/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
github, javascript

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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
主要语言
JavaScript
星标
35.1k
派生
2k
平均合并
2 天 1 小时
30 天内合并 PR
9

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

maboloshi/github-chinese 的其他 Issue

查看 maboloshi/github-chinese 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。