Skip to content

feat(i18n): add Traditional Chinese (zh-TW) support with Cantonese TTS#421

Open
alvinets wants to merge 3 commits intoTHU-MAIC:mainfrom
alvinets:pr-95
Open

feat(i18n): add Traditional Chinese (zh-TW) support with Cantonese TTS#421
alvinets wants to merge 3 commits intoTHU-MAIC:mainfrom
alvinets:pr-95

Conversation

@alvinets
Copy link
Copy Markdown

Summary

Add full Traditional Chinese (zh-TW) language support including UI translations, language selector in generation toolbar, and Cantonese (zh-HK) TTS voice mapping. Also fixes browser-native-tts not playing sound during course generation and discussion mode.

Related Issues

  • Related to: Adding Traditional Chinese / zh-TW language support to OpenMAIC

Changes

1. zh-TW Language Support

  • Add zh-TW.json with Traditional Chinese translations (following i18n structure from PR refactor(i18n): migrate to i18next framework #331)
  • Add zh-TW entry to locales.ts with label '繁體中文' and short label 'TW'
  • Add language cycling in generation toolbar: zh-CN → zh-TW → en-US

2. Type Definitions

  • Update UserRequirements.language and SceneOutline.language types to include zh-TW
  • Add zh-TW support to generateInteractiveContent function

3. Cantonese TTS Voice Mapping (lib/audio/constants.ts)

  • Add LANGUAGE_TO_TTS_VOICE mapping for course language → TTS voice per provider
  • Add getVoiceForLanguage() function
  • Add LOCALE_TO_BROWSER_VOICE mapping: zh-TW → zh-HK (Cantonese)
  • Add getBrowserVoiceForLocale() function

4. Browser Native TTS Fixes

  • Settings TTS Test: Add locale-to-browser-TTS-language mapping (zh-TW → zh-HK), pass UI locale through preview
  • Discussion TTS: Add locale option to useBrowserTTS hook, fix fallback to browser-native-tts when no server TTS configured (prevents 500 API errors)
  • Course Playback: Add getCourseLanguage callback, pass course language from stage, use for browser TTS: zh-TW → zh-HK, zh-CN → zh-CN, en-US → en-US

5. Type Updates

  • Add getCourseLanguage to PlaybackEngineCallbacks type
  • Update stage.tsx to pass course language to playback engine

Type of Change

  • New feature (non-breaking change that adds functionality)
  • Bug fix (non-breaking change that fixes an issue)

Verification

Steps to reproduce / test

  1. Set UI language to Traditional Chinese (繁體中文) in header
  2. Create a new course and select zh-TW as the course language
  3. Generate the course and play it back - should hear Cantonese voice for browser TTS
  4. Start a discussion during playback - should hear browser TTS in the selected language
  5. In Settings → Audio Settings, test TTS with browser-native-tts provider - should play in correct language

What you personally verified

  • TypeScript compiles without errors
  • All 94 tests pass
  • Manual testing: Settings TTS test plays Cantonese when UI is zh-TW
  • Manual testing: Discussion TTS uses browser-native-tts without 500 errors when no server TTS configured

Evidence

  • CI passes (pnpm check && pnpm lint && npx tsc --noEmit)
  • Manually tested locally
  • Screenshots / recordings attached (if UI changes) - UI changes are minimal (language selector pill)

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • My changes do not introduce new warnings
image

## Summary
Add full Traditional Chinese language support including UI translations,
language selector in generation toolbar, and Cantonese TTS voice mapping.

## Changes

### 1. zh-TW Language Support
- Add zh-TW.json with Traditional Chinese translations (following i18n structure from PR THU-MAIC#331)
- Add zh-TW entry to locales.ts with label '繁體中文' and short label 'TW'
- Add language cycling in generation toolbar: zh-CN → zh-TW → en-US

### 2. Type Definitions
- Update UserRequirements.language and SceneOutline.language types to include zh-TW
- Add zh-TW support to generateInteractiveContent function

### 3. Cantonese TTS Voice Mapping (lib/audio/constants.ts)
- Add LANGUAGE_TO_TTS_VOICE mapping for course language → TTS voice per provider
- Add getVoiceForLanguage() function
- Add LOCALE_TO_BROWSER_VOICE mapping: zh-TW → zh-HK (Cantonese)
- Add getBrowserVoiceForLocale() function

### 4. Browser Native TTS Fixes

#### Settings TTS Test (browser-tts-preview.ts)
- Add locale-to-browser-TTS-language mapping (zh-TW → zh-HK)
- Pass UI locale through use-tts-preview to browser TTS preview

#### Discussion TTS (use-discussion-tts.ts + use-browser-tts.ts)
- Add locale option to useBrowserTTS hook for language selection
- Pass UI locale to browser TTS during discussion mode
- Fix: resolveVoiceForAgent now properly falls back to browser-native-tts
  when no server TTS providers are configured (prevents 500 API errors)

#### Course Playback (playback/engine.ts)
- Add getCourseLanguage callback to PlaybackEngineCallbacks
- Pass course language from stage to playback engine
- Use course language for browser TTS: zh-TW → zh-HK, zh-CN → zh-CN, en-US → en-US

### 5. Type Updates
- Add getCourseLanguage to PlaybackEngineCallbacks type (lib/playback/types.ts)
- Update stage.tsx to pass course language from stage to playback engine

## Verification
- TypeScript compiles successfully
- All 94 tests pass

## Notes
- Browser-native-tts uses 'default' voice for all agents (no per-agent gender voice)
- Each agent can have custom voiceConfig set in agent settings for server TTS providers
- When global TTS is set to browser-native-tts, discussion mode also uses browser TTS
Copy link
Copy Markdown
Contributor

@wyuc wyuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zh-TW translation looks good. Could you scope this PR down to just the UI locale support?

That would be two files:

  • lib/i18n/locales/zh-TW.json
  • lib/i18n/locales.ts (register the new locale)

The language selector, TTS voice mapping, and browser-native-tts fixes are separate concerns and would be easier to review as individual PRs.

Also note that the toolbar language pill and toolbar.languageHint key conflict with #412, which removed manual language selection in favor of LLM inference. Worth discussing that in a separate issue.

One more thing: zh-TW → zh-HK for TTS assumes Cantonese, but Taiwan users speak Mandarin. That deserves its own discussion too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants