-
Notifications
You must be signed in to change notification settings - Fork 9
Add Simplified Chinese localization and language selector #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iciker
wants to merge
3
commits into
PndaMan:main
Choose a base branch
from
iciker:feat/zh-cn-localization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Simplified Chinese localization completion — TDD evidence | ||
|
|
||
| ## Source and user journey | ||
|
|
||
| This work was derived directly from the request to eliminate the 418 remaining | ||
| English UI audit findings. No external plan file was used. | ||
|
|
||
| As a user who selects Simplified Chinese, I want every reviewed static Svelte UI | ||
| string to have a Chinese rendering, while technical identifiers and user-authored | ||
| content remain unchanged. | ||
|
|
||
| ## RED → GREEN evidence | ||
|
|
||
| | Guarantee | Test or command | Type | Result | Evidence | | ||
| |---|---|---|---|---| | ||
| | Every Svelte UI file is included in the localization audit | `bun test src/lib/i18n.test.ts` | Integration | PASS | The suite checks all 58 `.svelte` files. | | ||
| | The previous untranslated inventory is rejected | `bun test src/lib/i18n.test.ts` before the translation update | Regression | RED | The new assertion failed with 418 findings. | | ||
| | No reviewed static English copy remains without a translation or explicit technical classification | `bun test src/lib/i18n.test.ts` after the translation update | Regression | PASS | 13 tests passed; the global finding list is empty. | | ||
| | The standalone audit agrees with the regression test | `bun run i18n:audit` | Static audit | PASS | `0 untranslated static strings across 58 Svelte files`. | | ||
| | The localized application still type-checks and bundles | `bun run check` and `bun run build` | Build | PASS | Svelte reported 0 errors and 0 warnings; Vite completed the production build. | | ||
|
|
||
| ## Coverage and known gaps | ||
|
|
||
| `bun test --coverage src/lib/i18n.test.ts` reports 86.32% line coverage for the | ||
| static audit module. Aggregate coverage is 43.36% because the same module imports | ||
| the browser-only DOM observer from `i18n.ts`; the Bun test environment has no DOM | ||
| implementation and therefore cannot execute that path. Translation behavior, | ||
| dynamic patterns, user-content boundaries, and the full 58-file audit are covered. | ||
| The DOM observer itself remains a browser/E2E coverage gap. | ||
|
|
||
| The audit intentionally preserves four technical examples: a DOI placeholder, an | ||
| API-key placeholder, an author-name format, and the `Osaka Jade` theme name. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import { readdirSync, readFileSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { parse } from "svelte/compiler"; | ||
| import { translateText } from "../src/lib/i18n"; | ||
|
|
||
| const TECHNICAL_COPY = new Set([ | ||
| "10.xxxx/…", | ||
| "AIza…", | ||
| "Cortex", | ||
| "Esc", | ||
| "Groq", | ||
| "Last, F.; Last, F.", | ||
| "OpenAI", | ||
| "Osaka Jade", | ||
| "Tailscale", | ||
| "Rust · Tauri · Svelte", | ||
| "Omarchy ·", | ||
| "age", | ||
| "cortex", | ||
| "ffmpeg", | ||
| "mpv", | ||
| "rclone", | ||
| "sync", | ||
| "syncd", | ||
| "yt-dlp", | ||
| ]); | ||
|
|
||
| function isTechnicalCopy(source: string): boolean { | ||
| return TECHNICAL_COPY.has(source) | ||
| || /^(?:https?:\/\/|~\/|\/)[^ ]+$/.test(source) | ||
| || /^[A-Z][A-Z0-9_-]+(?:=|[-])?…?$/.test(source) | ||
| || /^[A-Z][A-Z0-9_]+=/.test(source) | ||
| || /^(?:[\w.-]+\/)+[\w.-]+$/.test(source) | ||
| || /^[\w.-]+\/$/.test(source) | ||
| || /^[\w.-]+:[\w.-]+$/.test(source) | ||
| || /^[a-z0-9]+(?:[-/.][a-z0-9]+)+$/.test(source) | ||
| || /^[a-z0-9]{30,}$/.test(source) | ||
| || /^…?[\w.-]+\.[a-z]{2,}$/.test(source) | ||
| || /^(?:docker compose|git pull|sudo |rclone |age-keygen)/.test(source) | ||
| || /^(?:[\w.-]+:)?[\w.-]+\.(?:com|edu|net|org)(?:\/\S*)?$/.test(source); | ||
| } | ||
|
|
||
| function hasSkipAttribute(value: Record<string, unknown>): boolean { | ||
| const attributes = value.attributes; | ||
| return Array.isArray(attributes) && attributes.some((attribute) => { | ||
| return attribute | ||
| && typeof attribute === "object" | ||
| && "name" in attribute | ||
| && attribute.name === "data-i18n-skip"; | ||
| }); | ||
| } | ||
|
|
||
| export function svelteFilesUnder(directory: string): string[] { | ||
| return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => { | ||
| const path = join(directory, entry.name); | ||
| if (entry.isDirectory()) return svelteFilesUnder(path); | ||
| return entry.isFile() && entry.name.endsWith(".svelte") ? [path] : []; | ||
| }); | ||
| } | ||
|
|
||
| export function findUntranslatedStaticCopy(files = svelteFilesUnder("src")): string[] { | ||
| const untranslated: string[] = []; | ||
| for (const file of files) { | ||
| const ast = parse(readFileSync(file, "utf8"), { filename: file }) as any; | ||
| const seen = new Set<object>(); | ||
| const visit = (value: any, parent: any = null, skipped = false) => { | ||
| if (!value || typeof value !== "object" || seen.has(value)) return; | ||
| seen.add(value); | ||
| const skipChildren = skipped || hasSkipAttribute(value); | ||
| if (!skipChildren && value.type === "Text" && typeof value.data === "string") { | ||
| const inAttribute = parent?.type === "Attribute" || parent?.type?.endsWith?.("Directive"); | ||
| const translatedAttribute = inAttribute && ["title", "placeholder", "aria-label"].includes(parent.name); | ||
| if (!inAttribute || translatedAttribute) { | ||
| const source = value.data.trim().replace(/\s+/g, " "); | ||
| if ( | ||
| /[A-Za-z]{2}/.test(source) | ||
| && !isTechnicalCopy(source) | ||
| && translateText(source, "zh-CN") === source | ||
| ) { | ||
| untranslated.push(`${file}: ${source}`); | ||
| } | ||
| } | ||
| } | ||
| for (const [key, child] of Object.entries(value)) { | ||
| if (key === "parent" || key === "metadata") continue; | ||
| if (Array.isArray(child)) child.forEach((item) => visit(item, value, skipChildren)); | ||
| else visit(child, value, skipChildren); | ||
| } | ||
| }; | ||
| visit(ast.html); | ||
| } | ||
| return untranslated.sort(); | ||
| } | ||
|
|
||
| if (import.meta.main) { | ||
| const findings = findUntranslatedStaticCopy(); | ||
| const counts = new Map<string, number>(); | ||
| for (const entry of findings) { | ||
| const file = entry.slice(0, entry.indexOf(":")); | ||
| counts.set(file, (counts.get(file) ?? 0) + 1); | ||
| } | ||
| const byFile = [...counts] | ||
| .map(([file, count]) => `${file}: ${count}`) | ||
| .join("\n"); | ||
| console.log(`${findings.length} untranslated static strings across ${svelteFilesUnder("src").length} Svelte files`); | ||
| if (byFile) console.log(byFile); | ||
| } |
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Protect the linked course name outside
Picker.userContent: trueprotects only course options rendered byPicker. When a subject is already linked,linkedCourse.fullname || linkedCourse.shortnameis rendered directly at Line 342 inside.sp-course. That selector is not inSKIP_SELECTOR, so the DOM translator can change the Moodle course name.Wrap the displayed course name in
data-i18n-skip.Proposed fix
🤖 Prompt for AI Agents