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

オープン
#809 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
9

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

maboloshi/github-chinese のほかの issue

maboloshi/github-chinese の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。