feat(F9-2i): translate route 接課程 glossary 固定譯名#76
Merged
Conversation
…ation_rules) POST /localization/translate 加選填 project_id:給了即現讀該課 glossary 的固定譯名 (to_translation_rules)併進 glossary 規則送翻譯,讓在地化術語前後一致。 - TranslateRequest 加 project_id(optional,向後相容、既有 caller 零影響) - _glossary_lang_candidates:canonical 區域碼↔glossary 短碼對齊(en-US→en, zh-CN/zh-TW 完整碼本就是 key) - _course_glossary_rules / _merge_glossary:顯式 glossary 在前、課程在後合併 - fail-soft(RFC §5):沒 pid / 課不存在 / 無 glossary / 無該語言譯名 / 讀檔出錯 → 沿用現行行為,絕不讓翻譯失敗;glossary 讀檔走 to_thread(R-3) - 完全不碰 review gate / 狀態機(只影響術語怎麼譯) - 新增 tests/test_localization_glossary.py 9 測(全 mock translate、tmp 隔離) 本機全套 2673 passed(3 個 QR/journal 字型像素為容器缺 Noto CJK 假象,CI 權威)。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
做什麼
把 per-course glossary 的固定譯名接進在地化翻譯 route(F9-2 的最後一塊 offline slice,對應
docs/JOB_COURSE_ASSOCIATION_RFC.md§4.3)。POST /localization/translate的TranslateRequest新增選填project_id:給了 → 以ProjectStore.get_glossary(project_id)現讀該課 glossary →to_translation_rules(target_lang)產固定譯名規則文字塊,與呼叫端顯式glossary合併後送translator.translate(glossary=...),讓在地化翻譯術語前後一致(同一個「阻尼比」不會一下 damping ratio 一下 damping coefficient)。為什麼
F9-2 前面已把 glossary 的 schema → 儲存 → API → 前端編輯 → 翻譯橋接(
to_translation_rules)與 render 旁白讀音(F9-2h)全接好,唯獨翻譯 route 還沒用上那條橋。這刀把它接起來,固定譯名在實際翻譯時生效。怎麼做(重點)
TranslateRequest加project_id(optional,向後相容、既有 caller 零影響)。_glossary_lang_candidates:canonical 區域碼 ↔ glossary 短碼對齊(en-US→en;zh-CN/zh-TW完整碼本就是 glossary key,完整碼優先命中、不誤退基底)。_course_glossary_rules/_merge_glossary:呼叫端顯式 glossary 在前、課程規則在後合併。project_id/ 課不存在(ProjectNotFoundError)/ 無 glossary / 該語言無譯名 / 讀檔出錯 → 一律回空課程規則、沿用現行行為,絕不讓翻譯失敗。asyncio.to_thread不阻 event loop。怎麼測
tests/test_localization_glossary.py9 測:注入固定譯名(含別名並排)/顯式+課程合併順序/完整區域碼命中/該語言無譯名不附/沒 pid·未知 pid·無 glossary·空白 pid 四種 fail-soft。translator.translate攔截送進去的 glossary 字串、不打真 Gemini;ProjectStore注入 tmp 隔離 = offline-first。Reviewer 決策點
LocalizeMenu傳project_id屬後續前端 slice(route 欄位選填、不破壞現況,故本 PR 不含);若希望同 PR 一起接前端可提出。https://claude.ai/code/session_01MaksgNhEj5whAHmmvTGqC1
Generated by Claude Code