openmaic-custom/package.json
杨慎 ad9e0ee7c6
refactor(i18n): migrate to i18next framework (#331)
* refactor(i18n): migrate to i18next framework

Replace hand-rolled i18n with i18next + react-i18next so that adding a
new language only requires dropping a JSON file in lib/i18n/locales/.

- Add i18next, react-i18next, i18next-browser-languagedetector deps
- Generate zh-CN.json / en-US.json from existing TS translation modules
- Rewrite lib/i18n/index.ts as a thin wrapper around i18n.t()
- Rewrite use-i18n hook to delegate to useTranslation(); external API
  (locale, setLocale, t) is unchanged so consumers need no changes
- SSR-safe: LanguageDetector only loaded on client side

Closes #327

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(i18n): use interpolation for greeting to support natural phrasing

Replace string concatenation (greeting + displayName) with two
i18next keys: greetingWithName (with {{name}} interpolation) and
greetingDefault (standalone, no name).

This lets each locale choose natural phrasing independently:
- zh-CN: "嗨,同学" / "嗨,Alice"
- en-US: "Hi there" / "Hi, Alice"
- Future locales can avoid gender issues by choosing genderless defaults

Also widen the t() type signature to accept interpolation options.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor(i18n): auto-discover locale files via dynamic import

Replace hardcoded zh-CN/en-US imports with i18next-resources-to-backend
and dynamic import(`./locales/${language}.json`). Bundler scans the
locales/ directory at build time, so adding a new language now requires
only dropping a JSON file — zero changes to existing code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(i18n): resolve hydration mismatch by deferring language detection

LanguageDetector ran during i18next init(), detecting browser language
before React hydrated — server rendered zh-CN while client switched to
en-US immediately, causing a hydration mismatch.

Fix: remove i18next-browser-languagedetector; init with a fixed lng
(zh-CN) so server and client agree on the first render. Language
detection is now done in I18nProvider's useEffect after hydration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor(i18n): remove hardcoded locale list from language detection

Replace manual locale validation and startsWith('zh') prefix matching
with i18next's built-in fallback mechanism. Now changeLanguage() is
called with navigator.language directly — if the exact locale has no
JSON file, i18next automatically falls back to fallbackLng.

Also widen Locale type from union to string so adding new languages
doesn't require modifying types.ts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat(i18n): add course language config with 11 languages and UI linkage

- Add lib/i18n/course-languages.ts with curated language list
  (zh-CN, zh-TW, en-US, ja, ko, fr, de, es, pt, ru, ar) including
  native labels and English prompt names
- Course language defaults to UI locale on first visit; once user
  explicitly picks a language, that choice persists across sessions
- Replace toggle button with dropdown selector showing native labels
- Widen language types from 'zh-CN'|'en-US' to string throughout
- Fix hardcoded language ternaries in LLM prompt injection:
  - prompt-builder.ts: use getCourseLanguagePromptName()
  - classroom-generation.ts: remove normalizeLanguage() that forced
    all non-English to zh-CN
  - PBL system prompt, agent templates, generate-pbl: append language
    instruction for non-zh/en languages
  - quiz-grade API: add language suffix for grading feedback

Closes #327

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(quiz): use course language instead of UI locale for grading

quiz-view was passing the UI locale to the grading API, causing AI
feedback to follow the student's answer language instead of the course
language. Now reads stage.language from the store.

Also strengthen the grading prompt: explicitly instruct the LLM to
write comments in the course language regardless of the student's
input language.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* revert: remove course language config and quiz fix from i18next branch

Reverts f7bd6bd and 5bb5133 — these are independent features that
should go into a separate branch/PR.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore(i18n): regenerate locale JSON after merging latest main

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore(i18n): remove obsolete TS translation files

These files are replaced by lib/i18n/locales/*.json and are no longer
imported anywhere in the codebase.

Removed: chat.ts, common.ts, generation.ts, settings.ts, stage.ts

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* style(i18n): fix prettier formatting in locale JSON files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor(i18n): replace hardcoded language options with central locale registry

Add lib/i18n/locales.ts as a single source of truth for supported languages.
Language selectors in header and homepage now render dynamically from this
registry. Also adds supportedLngs to i18next config so unsupported languages
fall back correctly. Adding a new language now only requires a JSON file and
one line in the registry.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(i18n): add missing rename keys to JSON locale files

Add classroom.rename, classroom.renamePlaceholder, and
classroom.renameFailed that were added to generation.ts on main
but missing from the JSON locale files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor(i18n): extract LanguageSwitcher, restore type safety, fix locale resolution

- Extract shared <LanguageSwitcher /> component from page.tsx and header.tsx
- Derive Locale type from supportedLocales registry (as const satisfies)
- Add resolveLocale() to match browser language prefixes (e.g. 'en' → 'en-US')
- Remove config.ts changes (nonExplicitSupportedLngs + inline resources) that
  broke translation loading when combined with resourcesToBackend

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(i18n): use i18next double-brace interpolation instead of manual .replace()

- Convert all {var} placeholders in locale JSONs to {{var}} (i18next default)
- Replace .replace('{var}', value) calls with t(key, {var: value}) in all
  consuming components: lecture-notes-view, pbl-renderer, use-pbl-chat,
  generation-preview, whiteboard-history, agent-settings
- Widen t() type signature in handleIssueComplete to accept interpolation options

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat(i18n): unify greeting with default nickname, add translation guide

- Remove greetingDefault key; greeting always uses greetingWithName
  with displayName (falls back to profile.defaultNickname)
- Change en-US defaultNickname from "Student" to "Learner"
- Add TRANSLATION_GUIDE.md documenting how to add languages and
  explaining keys with non-obvious UX design intent

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 12:04:42 +08:00

135 lines
4.0 KiB
JSON

{
"name": "openmaic",
"version": "0.1.0",
"private": true,
"license": "AGPL-3.0",
"engines": {
"node": ">=20.9.0"
},
"scripts": {
"postinstall": "cd packages/mathml2omml && npm run build && cd ../pptxgenjs && npm run build",
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "eslint",
"check": "prettier . --check",
"format": "prettier . --write",
"test": "vitest run",
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui"
},
"dependencies": {
"@ai-sdk/anthropic": "^3.0.23",
"@ai-sdk/google": "^3.0.13",
"@ai-sdk/openai": "^3.0.13",
"@ai-sdk/react": "^3.0.44",
"@base-ui/react": "^1.1.0",
"@copilotkit/backend": "^0.37.0",
"@copilotkit/runtime": "^1.51.2",
"@fontsource-variable/inter": "^5.2.8",
"@langchain/core": "^1.1.16",
"@langchain/langgraph": "^1.1.1",
"@modelcontextprotocol/sdk": "^1.27.1",
"@napi-rs/canvas": "^0.1.88",
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-popover": "^1.1.15",
"@radix-ui/react-slider": "^1.3.6",
"@radix-ui/react-switch": "^1.2.6",
"@radix-ui/react-use-controllable-state": "^1.2.2",
"@types/js-yaml": "^4.0.9",
"@xyflow/react": "^12.10.0",
"ai": "^6.0.42",
"animate.css": "^4.1.1",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
"copilotkit": "^0.0.58",
"dexie": "^4.2.1",
"echarts": "^6.0.0",
"embla-carousel-react": "^8.6.0",
"file-saver": "^2.0.5",
"geist": "^1.7.0",
"i18next": "^26.0.1",
"i18next-resources-to-backend": "^1.2.1",
"immer": "^11.1.3",
"js-yaml": "^4.1.1",
"jsonrepair": "^3.13.2",
"jszip": "^3.10.1",
"katex": "^0.16.33",
"lodash": "^4.17.21",
"lucide-react": "^0.562.0",
"mathml2omml": "workspace:*",
"mitt": "^3.0.1",
"motion": "^12.27.5",
"nanoid": "^5.1.6",
"next": "16.1.2",
"next-themes": "^0.4.6",
"openai": "^4.104.0",
"partial-json": "^0.1.7",
"pptxgenjs": "workspace:*",
"pptxtojson": "^1.11.0",
"prosemirror-commands": "^1.7.1",
"prosemirror-dropcursor": "^1.8.2",
"prosemirror-gapcursor": "^1.4.0",
"prosemirror-history": "^1.5.0",
"prosemirror-inputrules": "^1.5.1",
"prosemirror-keymap": "^1.2.3",
"prosemirror-model": "^1.25.4",
"prosemirror-schema-basic": "^1.2.4",
"prosemirror-schema-list": "^1.5.1",
"prosemirror-state": "^1.4.4",
"prosemirror-view": "^1.41.5",
"radix-ui": "^1.4.3",
"react": "19.2.3",
"react-dom": "19.2.3",
"react-i18next": "^17.0.1",
"shadcn": "^3.6.3",
"sharp": "^0.34.5",
"shiki": "^3.21.0",
"sonner": "^2.0.7",
"streamdown": "^2.1.0",
"svg-arc-to-cubic-bezier": "^3.2.0",
"svg-pathdata": "^8.0.0",
"tailwind-merge": "^3.4.0",
"temml": "^0.13.1",
"tinycolor2": "^1.6.0",
"tokenlens": "^1.3.1",
"tw-animate-css": "^1.4.0",
"undici": "^7.22.0",
"unpdf": "^1.4.0",
"use-stick-to-bottom": "^1.1.1",
"zod": "^4.3.5",
"zustand": "^5.0.10"
},
"devDependencies": {
"@playwright/test": "^1.58.2",
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-node-resolve": "^16.0.1",
"@tailwindcss/postcss": "^4",
"@types/file-saver": "^2.0.7",
"@types/katex": "^0.16.8",
"@types/lodash": "^4.17.23",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"@types/tinycolor2": "^1.4.6",
"eslint": "^9",
"eslint-config-next": "16.1.2",
"prettier": "3.8.1",
"rollup": "^4.35.0",
"rollup-plugin-typescript2": "^0.36.0",
"tailwindcss": "^4",
"tslib": "^2.8.0",
"typescript": "^5",
"vitest": "^4.1.0",
"vue-to-react": "^1.0.0"
},
"pnpm": {
"ignoredBuiltDependencies": [
"sharp",
"unrs-resolver"
]
},
"packageManager": "pnpm@10.28.0+sha512.05df71d1421f21399e053fde567cea34d446fa02c76571441bfc1c7956e98e363088982d940465fd34480d4d90a0668bc12362f8aa88000a64e83d0b0e47be48"
}