feat: add Traditional Chinese (zh-TW) language support#95
Open
alvinets wants to merge 16 commits intoTHU-MAIC:mainfrom
Open
feat: add Traditional Chinese (zh-TW) language support#95alvinets wants to merge 16 commits intoTHU-MAIC:mainfrom
alvinets wants to merge 16 commits intoTHU-MAIC:mainfrom
Conversation
949e1ba to
1976887
Compare
Author
|
Lint & Typecheck done |
- Add zh-TW locale to i18n system with full translations for all UI text - Add Traditional Chinese option to UI language selector (header dropdown) - Add 3-option course generation language selector (简体/繁体/EN) - Auto-select Cantonese TTS voice when generating in Traditional Chinese - Add zh-HK-HiuGaNeural and zh-HK-HiuManNeural Cantonese voices to Azure TTS - Add LANGUAGE_TO_TTS_VOICE mapping and getVoiceForLanguage() helper - Sync TTS config to audio player for browser-native-tts support - Add export guard with toast warning for empty slides
Fix TS2345 errors in scene-generator.ts and outline-generator.ts where 'zh-TW' was not assignable to SceneOutline.language type
- Add LOCALE_TO_BROWSER_VOICE mapping and getBrowserVoiceForLocale() helper - use-i18n.tsx: auto-switch TTS voice when user changes UI locale - use-i18n.tsx: sync TTS voice on initial locale hydration from localStorage - Remove course-language TTS auto-switch from app/page.tsx (UI locale controls browser TTS instead)
Previously, playBrowserTTS would override the user's explicit voice setting (e.g. zh-HK for Traditional Chinese locale) with text auto-detection, causing Cantonese text to be spoken in Mandarin. Now: user-selected voice always takes priority. 1. Try exact voice name/URI match 2. Try language code match (zh-HK, zh-CN, en-US) 3. If no match but user set preference → set utterance.lang directly (browser uses its best voice for that language) 4. Only use text auto-detection when user has NO preference
…thFallback Pre-generated audio (from IndexedDB) was played first even when browser TTS was selected, causing stale Mandarin audio to play after switching locale. Now: if browser-native-tts is configured, always use playBrowserTTS directly so the user's current voice setting (locale-synced) is respected.
Previously, engine called play(audioId, audioUrl) where audioUrl (server-generated Mandarin audio) took priority over browser TTS, making locale voice switch ineffective. Now play() skips audioUrl when browserTTSConfig is set, letting playWithFallback use browser TTS with the current locale-synced voice (zh-HK for 繁體中文).
…ice found Previously, if ttsVoice was set to 'zh-HK' but no voice had that exact voiceURI, the engine fell back to text auto-detection (Mandarin or English only), ignoring the user's explicit voice preference. Now: when user sets a non-default voice preference but no matching voice is found, utterance.lang is set directly to the user's preferred language code (zh-HK), so the browser uses its best available voice for that language.
314036f to
7d3a1db
Compare
c507183 to
7d3a1db
Compare
… TTS - Add zh-TW locale type and translation files (re-export zh-CN as base) - Register zh-TW in i18n translations registry - Add LOCALE_TO_BROWSER_VOICE mapping: zh-TW → zh-HK (Cantonese) - use-i18n.tsx: auto-switch TTS voice when user changes UI locale - useBrowserTTS hook: respect ttsVoice setting with language code fallback - action/engine.ts: add browser TTS fallback for lecture speech when no pre-generated audio - speakWithBrowserTTS: respects user's ttsVoice, sets utterance.lang when no voice match Browser TTS voice now follows UI locale (top-right language button): - 繁體中文 → zh-HK (Cantonese) - 简体中文 → zh-CN (Mandarin) - EN → en-US
Resolved merge conflicts while preserving TW (Traditional Chinese) support: - components/stage.tsx: Use local version with BrowserTTSConfig import - lib/audio/constants.ts: Added TW voice mappings and locale-to-voice functions - TW translations preserved in lib/i18n/ TW-specific changes preserved: - LOCALE_TO_BROWSER_VOICE maps 'zh-TW' to 'zh-HK' (Cantonese) - LANGUAGE_TO_TTS_VOICE maps 'zh-TW' to Cantonese voices for each provider - getBrowserVoiceForLocale() function for UI locale voice resolution - TW voice entries in browser-native-tts provider
Resolved merge conflicts while preserving TW (Traditional Chinese) support: - components/stage.tsx: Use local version with BrowserTTSConfig import - lib/audio/constants.ts: Added TW voice mappings and locale-to-voice functions - TW translations preserved in lib/i18n/ TW-specific changes preserved: - LOCALE_TO_BROWSER_VOICE maps 'zh-TW' to 'zh-HK' (Cantonese) - LANGUAGE_TO_TTS_VOICE maps 'zh-TW' to Cantonese voices for each provider - getBrowserVoiceForLocale() function for UI locale voice resolution - TW voice entries in browser-native-tts provider
- Add onSoftPause?: () => void to RoundtableProps interface - Add onSoftPause to Roundtable component destructuring props Fixes type error in Stage component
- TW (zh-TW) language support with 繁體中文 translations - Cantonese (zh-HK) TTS voice for TW locale - Browser-native-tts auto-switch on locale change - TW translations embedded in lib/i18n/ files - LOCALE_TO_BROWSER_VOICE mapping for UI locale resolution - Added missing onSoftPause prop to RoundtableProps - Resolved conflicts in components/stage.tsx and lib/audio/constants.ts
fix prettier --check
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.
Summary
Add full Traditional Chinese (zh-TW) language support across the OpenMAIC platform, including UI translations, course generation language selection, and Cantonese TTS auto-switching.
Changes
i18n & UI
common,stage,chat,generation, andsettingsmodules (~900 Traditional Chinese strings)Course Generation
zh-CN | en-UStozh-CN | zh-TW | en-USSceneOutline,pblConfig, andgenerateInteractiveContentlanguage types to includezh-TWBrowser TTS Voice
LOCALE_TO_BROWSER_VOICE:zh-TW → zh-HK(Cantonese),zh-CN → zh-CN(Mandarin),en-US → en-USsetLocale()auto-switches TTS voice when user changes UI localeplayBrowserTTSChunk: setsutterance.lang = ttsVoicewhen no exact voice match found, so browser uses best available voice for that languageplayWithFallback: prioritizes browser TTS over pre-generated audioplay(): skipsaudioUrlwhen browser TTS configured (prevents stale server audio)Azure TTS
zh-HK-HiuGaNeural(曉佳) andzh-HK-HiuManNeural(曉曼)LANGUAGE_TO_TTS_VOICEmapping +getVoiceForLanguage()for all 5 TTS providersBug Fixes
play(audioId, audioUrl)andaudioUrlfield inSpeechActionFiles Changed
lib/i18n/types.tszh-TWtoLocaleunionlib/hooks/use-i18n.tsxLOCALE_TO_BROWSER_VOICEsync onsetLocale+ hydrationlib/i18n/common.tscommonZhTWtranslationslib/i18n/stage.tsstageZhTWtranslationslib/i18n/chat.tschatZhTWtranslationslib/i18n/generation.tsgenerationZhTWtranslationslib/i18n/settings.tssettingsZhTWtranslationslib/i18n/index.tszh-TWin translationslib/audio/constants.tsLANGUAGE_TO_TTS_VOICE+LOCALE_TO_BROWSER_VOICE+getVoiceForLanguage+getBrowserVoiceForLocalelib/types/generation.tsSceneOutline.languageandpblConfig.languageincludezh-TWlib/generation/scene-generator.tsgenerateInteractiveContentparam type includeszh-TWlib/types/action.tsaudioUrlfield toSpeechActionlib/playback/engine.tsplayBrowserTTSrespectsttsVoicelang; adapted toplay(audioId, audioUrl)lib/utils/audio-player.tsplay()skipsaudioUrlwhen browser TTS;playWithFallbackprioritizes browser TTS;playBrowserTTSrespects user preferencelib/export/use-export-pptx.tscomponents/header.tsxcomponents/generation/generation-toolbar.tsxcomponents/stage.tsxBrowserTTSConfigsyncapp/page.tsxType of Change
Verification
npx tsc --noEmitpasses (0 errors)npx eslintpasses (0 errors, 0 warnings)Checklist