Pull Request: Add i18n Infrastructure and Chinese (zh-CN) Localization#554
Open
smryyyyy wants to merge 1 commit into
Open
Pull Request: Add i18n Infrastructure and Chinese (zh-CN) Localization#554smryyyyy wants to merge 1 commit into
smryyyyy wants to merge 1 commit into
Conversation
- Add lightweight translation system (src/language/) with t() function, zero external dependencies - Add en.json and zh-CN.json covering ~900 UI strings - Convert 60+ source files from hardcoded English to t() calls - Add language selector on welcome page and in Settings - Fix module-level t() timing issues with lazy initialization - Translate welcome page, sidebar, settings, dialogs, commands, toasts, shortcuts, extensions hub, file dialogs, and status bar - Add cn_README.md with full Chinese documentation - Update HTML lang attributes to zh-CN - Fix pre-commit lint errors in settings-overlay.ts - Default language is English, switchable to Chinese
|
@smryyyyy is attempting to deploy a commit to the tmustier's projects Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
Simply put |
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.
Pull Request: Add i18n Infrastructure and Chinese (zh-CN) Localization
Summary
This PR adds a lightweight internationalization (i18n) system and complete Simplified Chinese (zh-CN) translation to Pi for Excel.
Motivation: Pi for Excel has a growing user base in China. Previously all UI text was hardcoded in English, making it inaccessible to non-English speakers. This PR introduces a translation framework with zero third-party dependencies and provides a complete Chinese localization out of the box.
Architecture
Translation System (
src/language/)A minimal, zero-dependency translation function that avoids adding any bundle overhead:
Design decisions:
{placeholder}syntaxAPI
Language Switching
Two entry points for switching language:
Both save the preference to
settings.languageand reload the page.Changes by Category
Core Infrastructure (4 new files)
src/language/index.ts— Translation functionsrc/language/locales/en.json— English stringssrc/language/locales/zh-CN.json— Chinese stringscn_README.md— Chinese documentationModified Files (74 files)
Key Fixes
Module-level
t()timing bug — Several files hadt()calls in module-levelconstdeclarations that executed beforeinitLanguage()was called. Fixed by converting to lazy getter functions:src/experiments/flags.ts—EXPERIMENTAL_FEATURES→getFeatures()src/commands/builtins/settings-overlay.ts—SETTINGS_TABS→getSettingsTabs()src/commands/builtins/shortcuts-overlay.ts—SHORTCUT_GROUPS→getShortcutGroups()src/ui/confirm-dialog.ts,src/ui/text-input-dialog.ts— Error constants → getter functionssrc/taskpane/status-context.ts— Context constants → getter functionssrc/taskpane/status-popovers.ts— Level labels/hints → getter functionssrc/extensions/permissions.ts— Capability descriptors → getter functionMissing imports — Added
import { t }where it was missing:src/ui/files-dialog-filtering.tssrc/ui/files-dialog.tssrc/ui/files-dialog-status.tssrc/compat/thinking-duration.tssrc/workbook/context.tssrc/commands/builtins/rules-overlay.tsHardcoded relative date —
src/commands/builtins/overlay-relative-date.tsandsrc/ui/files-dialog.tshad hardcoded "just now", "m ago", "h ago" strings → made translatableExecution mode toast —
src/execution/controller.tshad`${label} mode.`hardcoded → made translatableTesting
npm run dev— Dev server starts successfully (HTTP 200)git diff --stat— 78 files changed, 3365 insertions, 1144 deletionsfiles-dialog-actions.tsandrender-csv-table.ts) are upstream issues, not introduced hereManual Verification
Adding a New Language
Adding another language requires only:
src/language/locales/{lang}.jsonwith all keys translatedsrc/language/index.tsScreenshots
中文版本
摘要
此 PR 为 Pi for Excel 添加了轻量级国际化(i18n)系统和完整的简体中文(zh-CN)翻译。
动机: Pi for Excel 在中国拥有日益增长的用户群。此前所有 UI 文本均硬编码为英文,非英语用户无法直接使用。此 PR 引入了一个零第三方依赖的翻译框架,并提供开箱即用的完整中文本地化。
架构
翻译系统位于
src/language/,包含:index.ts—t()翻译函数、initLanguage()初始化、getLanguage()获取当前语言locales/en.json— 英文原文(约 900 条,作为兜底)locales/zh-CN.json— 中文翻译(约 900 条)设计原则:不引入任何 i18n 第三方库,对 Office WebView 保持零包体积增长。英文为兜底语言,未翻译的 key 自动显示英文原文。
语言切换
两种方式:
切换后保存到
settings.language并自动刷新页面。文件变更
关键修复
t()调用在initLanguage()之前执行的时序问题(7 处)import { t }导致的运行时错误