4.7 KiB
4.7 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
RikkaHub I18n is an AI-powered translation manager for Android string resources with an interactive Terminal UI (TUI). This tool manages translations for the main RikkaHub Android application, which is a native LLM chat client supporting multiple AI providers.
Architecture Overview
Core Components
- Config System (
src/config.ts): YAML-based configuration loader for targets, modules, and AI providers - XML Parser (
src/xml-parser.ts): Android string resource parser and generator with merge capabilities - Translator (
src/translator.ts): AI-powered translation service with Google Gemini and OpenAI support - Module Loader (
src/module-loader.ts): Multi-module Android project scanner and statistics calculator - TUI Components (
src/tui/): Interactive terminal interface built with React and Ink
Key Technologies
- TypeScript: Primary language with strict configuration
- React + Ink: Terminal UI framework for interactive components
- Vercel AI SDK: Unified AI provider interface (@ai-sdk/google, @ai-sdk/openai)
- xml2js: XML parsing and building for Android string resources
- YAML: Configuration file format
Development Commands
Development
# Start the interactive TUI (recommended for development)
npm run dev
# or
bun run dev
Build and Production
# Compile TypeScript to dist/
npm run build
# Run compiled version
npm start
Configuration
Environment Setup
Create .env file with AI provider API keys:
# For Google Gemini (default)
GOOGLE_GENERATIVE_AI_API_KEY=your_gemini_api_key_here
# For OpenAI
OPENAI_API_KEY=your_openai_api_key_here
Project Configuration (config.yml)
# Target languages (Android resource directory suffixes)
targets:
- zh # Simplified Chinese
- ja # Japanese
- zh-rTW # Traditional Chinese
# Workspace root relative to i18n directory
workspaceRoot: ".."
# Android modules to scan for string resources
modules:
- app
- ai
- highlight
- search
- rag
# AI provider configuration
provider:
type: google # "google" or "openai"
model: gemini-2.5-flash
File Structure and Paths
Android String Resource Paths
- Default strings:
{modulePath}/src/main/res/values/strings.xml - Localized strings:
{modulePath}/src/main/res/values-{locale}/strings.xml
Key Files
config.yml: Main configurationlogs.txt: Translation process logs (auto-generated)package.json: Dependencies and scriptstsconfig.json: TypeScript configuration with strict settings
Translation Process
Workflow
- Scans configured Android modules for
strings.xmlfiles - Compares default strings with existing translations
- Calculates completion statistics per module/language
- Uses AI to translate missing entries with context awareness
- Preserves Android formatting (
%1$d,%1$s,\\n,\\') - Saves translations to appropriate
values-{locale}/strings.xmlfiles
TUI Navigation
- Module Selection: ↑↓ navigate, Enter select, shows completion progress
- Language Selection: ↑↓ navigate, Enter select, shows translation statistics
- Translation Table: ↑↓ navigate,
eedit,ttranslate all,ffilter missing,qback - Edit Mode: Type to edit, Enter save, Esc cancel
AI Translation Features
- Context-aware translations with module and key information
- Automatic rate limiting with 100ms delays
- Error handling with fallback to original text
- Comprehensive logging to
logs.txt - Support for Android string formatting preservation
Supported Languages
Current target languages with full language names for AI context:
zh: Simplified Chinese (简体中文)zh-rTW: Traditional Chinese (繁體中文)ja: Japanese (日本語)- Additional languages can be added to
LANGUAGE_NAMESmapping
Development Guidelines
Code Style
- Follows strict TypeScript configuration
- Uses ESNext modules with bundler resolution
- Implements proper error handling and logging
- React functional components with hooks
Adding New AI Providers
Extend getModel() function in translator.ts and add configuration options to support additional Vercel AI SDK providers.
Module Detection
The tool automatically scans for Android modules containing src/main/res/values/strings.xml files. Non-existent modules are skipped with warnings.
Error Handling
- File permission issues: Check write access to Android module directories
- API rate limits: Built-in delays and retry logic
- Missing translations: Filter functionality to focus on incomplete items
- API key issues: Verify
.envconfiguration and quota