Skip to content

Conversation

@taniar88
Copy link

Summary

Implements dynamic internationalization (i18n) language loading system that fetches available languages from backend
API and loads translation files on-demand.

Related PRs

  • Backend: #346 (Open-LLM-VTuber/Open-LLM-VTuber)

Key Features

  • Backend API Integration: Fetches available languages from /api/languages endpoint
  • Dynamic Language Loading: Loads translation files on-demand using Vite glob imports
  • Korean Translation: Complete Korean translation (139 keys) added
  • Fallback System: Graceful fallback when API is unavailable
  • Memory Leak Prevention: Proper useEffect cleanup with cancellation flags

Critical Bug Fix

Fixed React Hook order bug caused by asynchronous i18n initialization:

  • Before: Async initialization at module load → Hook order issues
  • After: Synchronous initialization for base languages (en, zh), lazy loading for additional languages
  • Result: Hook order preserved, no runtime errors

Files Changed

  • FRONTEND_INTEGRATION_PLAN.md - Implementation plan and warnings
  • src/renderer/src/utils/languageApi.ts - Backend API integration
  • src/renderer/src/utils/languageNames.ts - Fallback language mapping
  • src/renderer/src/types/language.ts - TypeScript type definitions
  • src/renderer/src/i18n.ts - Core i18n with dynamic loading
  • src/renderer/src/components/sidebar/setting/general.tsx - Language selector UI
  • src/renderer/src/locales/ko/translation.json - Korean translation

Testing

  • ✅ TypeScript compilation passes
  • ✅ ESLint passes (no errors or warnings)
  • ✅ No any types used
  • ✅ useEffect cleanup implemented
  • ✅ Korean language selection works
  • ✅ Backend API fallback works

How to Test

  1. Ensure backend server is running with PR #346 changes
  2. Open frontend settings
  3. Language dropdown should show all backend-provided languages with native labels
  4. Select Korean (한국어) - UI should switch to Korean
  5. Verify no console errors
  6. Test with backend offline - should fallback to en/zh only

Notes

  • This PR depends on backend changes in Open-LLM-VTuber PR #346
  • Both PRs should be merged together for full functionality

## Summary
- Implement dynamic language loading system that fetches available languages from backend API
- Add Korean translation file with complete UI translations
- Fix critical i18n initialization bug that caused React Hook order issues

## Key Features
1. **Backend API Integration**
   - Fetch available languages from `/api/languages` endpoint
   - Display language labels provided by backend (no frontend mapping needed)
   - Fallback to default languages (en, zh) if API fails

2. **Dynamic Language Loading**
   - Base languages (en, zh) loaded synchronously to prevent Hook errors
   - Additional languages loaded dynamically when user selects them
   - Uses Vite glob import pattern for compatibility

3. **Korean Translation**
   - Added complete Korean translation file (ko/translation.json)
   - 139 translation keys covering all UI elements
   - Natural Korean expressions suitable for UI context

## Bug Fix
- Fixed React Hook order error caused by asynchronous i18n initialization
- Changed from async initialization to sync initialization with dynamic loading
- Prevents "useTranslation: You will need to pass in an i18next instance" error

## Technical Details
- Uses i18n.addResourceBundle() for dynamic language loading
- Implements useEffect cleanup to prevent memory leaks
- Type-safe with TypeScript interfaces (LanguageInfo, LanguageApiResponse)

## Files Changed
- Modified: i18n.ts, general.tsx
- Added: languageApi.ts, languageNames.ts, language.ts
- Added: locales/ko/translation.json
- Docs: FRONTEND_INTEGRATION_PLAN.md

## Testing
- Language dropdown displays en, zh, ko from backend
- Language switching works correctly
- UI updates to Korean when selected
- No React Hook errors in console

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello @taniar88, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 애플리케이션의 국제화(i18n) 기능을 대폭 개선하여 언어 관리를 더욱 유연하고 확장 가능하게 만듭니다. 백엔드 API와 연동하여 사용 가능한 언어 목록을 동적으로 가져오고, 번역 파일을 필요할 때만 로드함으로써 프론트엔드 코드 변경 없이 새로운 언어를 쉽게 추가할 수 있도록 합니다. 또한, 한국어 지원을 추가하고, 기존의 React Hook 순서 버그를 해결하여 전반적인 안정성과 사용자 경험을 향상시킵니다.

Highlights

  • 동적 i18n 언어 로딩 시스템 구현: 백엔드 API에서 사용 가능한 언어를 가져와 필요에 따라 번역 파일을 로드하는 시스템을 구현했습니다.
  • Vite glob import를 사용한 온디맨드 번역 파일 로딩: Vite의 빌드 시 정적 분석 제약을 해결하기 위해 import.meta.glob()을 활용하여 번역 파일을 동적으로 로드합니다.
  • 한국어 번역 추가: 139개의 키를 포함하는 완전한 한국어 번역 파일(src/renderer/src/locales/ko/translation.json)이 추가되었습니다.
  • 견고한 폴백 시스템: 백엔드 API를 사용할 수 없을 때 기본 언어(영어, 중국어)로 안전하게 폴백하는 메커니즘을 구현했습니다.
  • 메모리 누수 방지 및 React Hook 순서 버그 수정: useEffect 클린업 로직을 통해 비동기 작업 중 컴포넌트 언마운트 시 발생할 수 있는 메모리 누수를 방지하고, 비동기 i18n 초기화로 인한 React Hook 순서 문제를 해결하여 런타임 오류를 방지합니다.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a dynamic language loading system, which is a great enhancement for internationalization. The implementation correctly uses Vite's glob imports for on-demand loading and adds Korean translations. The code is well-structured, especially the use of cleanup functions in useEffect to prevent memory leaks.

I've identified a few areas for improvement:

  • There's a potential bug in general.tsx where component state is updated directly during the render phase. This should be moved to a useEffect hook.
  • The implementation plan in FRONTEND_INTEGRATION_PLAN.md seems to be out of sync with the actual code, which could be confusing for future maintenance.
  • For better maintainability, I've suggested replacing a hardcoded URL with a constant and translating some Korean code comments into English.

Overall, this is a solid contribution. Addressing these points will improve the code's correctness and maintainability.

Applied all fixes from PR #18 code review:

HIGH PRIORITY:
- Fixed render-phase state update in general.tsx
  - Moved language sync logic from render to useEffect
  - Prevents React purity rule violations
  - Avoids potential infinite render loops

MEDIUM PRIORITY:
- Extracted hardcoded URL to DEFAULT_BASE_URL constant
  - Created DEFAULT_BASE_URL in languageApi.ts
  - Updated all references in languageApi.ts and general.tsx
  - Improves maintainability and consistency

- Translated Korean comments to English
  - Updated comments in languageApi.ts
  - Updated comments in languageNames.ts
  - Updated comments in language.ts
  - Updated comments in general.tsx
  - Improves accessibility for international contributors

- Updated FRONTEND_INTEGRATION_PLAN.md
  - Reflected actual implementation details
  - Added critical bug fix documentation
  - Added new warning about render-phase state updates
  - Updated implementation status (all tasks complete)
  - Translated key sections to English

Files modified:
- src/renderer/src/components/sidebar/setting/general.tsx
- src/renderer/src/utils/languageApi.ts
- src/renderer/src/utils/languageNames.ts
- src/renderer/src/types/language.ts
- FRONTEND_INTEGRATION_PLAN.md

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@taniar88 taniar88 closed this Jan 25, 2026
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.

1 participant