How kimrenny/i18nh works
Purpose and Runtime
Localization AI is an Electron desktop app for discovering, comparing, editing, translating, and safely writing JSON localization files. The renderer is React/TypeScript via Vite; privileged filesystem and translation-network work belongs in Electron’s main process. Main entry points are electron/main/index.ts, electron/preload/index.ts, and src/main.tsx.
Process Boundary and IPC
Electron main owns window lifecycle, folder/file access, atomic disk writes, and requests to translation providers in electron/main/index.ts, electron/main/aiService.ts, and electron/main/freeTranslationService.ts. The preload bridge in electron/preload/index.ts exposes a typed, constrained window.electronAPI contract defined by src/types/electron.d.ts; the React renderer does not directly use Node APIs or provider credentials.
Renderer Orchestration
src/App.tsx is the application-level coordinator for selected files, comparison state, settings, editing, translation actions, review, and refresh after writes. UI is organized around localization inspection and action surfaces: src/components/localization/LocalizationTree.tsx, src/components/localization/LocalizationSummary.tsx, and src/components/settings/SettingsModal.tsx. Review-oriented flows are separated into src/components/localization/AiTranslationConfirmModal.tsx and src/components/localization/BatchTranslationModal.tsx.
Localization Analysis Pipeline
JSON localization content is parsed into usable key representations by src/services/localizationParser.ts; src/services/localizationComparator.ts applies the union-of-keys comparison model across selected files, distinguishing missing paths from present-but-empty strings. Tree and navigation projections support hierarchical inspection and direct traversal of unresolved items through src/services/localizationTree.ts and src/services/missingKeyNavigator.ts. Core domain structures are centralized in src/types/localization.ts.
Editing and Persistence Safety
Manual edits, adding absent keys, and approved translation applications ultimately update the selected file through the Electron boundary. src/services/localizationWriter.ts owns JSON reconstruction/formatting and atomic-write semantics, while src/components/localization/AddMissingKeysModal.tsx provides the explicit missing-key insertion workflow. Writes are intentionally action-triggered; successful persistence should feed back into a fresh comparison state.
Translation Selection and Execution
Settings define the active engine, provider/model, credentials, endpoint, and review policy through src/types/settings.ts and src/components/settings/SettingsModal.tsx. Provider metadata/presets live in src/services/aiProviderRegistry.ts and src/services/freeProviderRegistry.ts. Main-process integrations target cloud AI providers, local Ollama, LibreTranslate endpoints, and MyMemory; no translation request is needed for normal file analysis.
Batch, Reliability, and Validation Controls
Single and batch AI flows are composed in src/services/aiTranslation.ts and src/services/aiBatchTranslation.ts. src/services/aiBatchPlanner.ts groups work by language pair/file, chunks requests, and supports splitting oversized batches; execution handles retry/backoff and partial failures. Every generated result crosses src/services/aiResponseValidator.ts, which enforces preservation of placeholders, formatting syntax, escape sequences, and HTML/XML markup before it can be reviewed or persisted. src/services/aiEditPolicy.ts determines whether validated proposals require user approval or may be applied directly.
Main entry points: index.ts Main process services · App.tsx App coordinator · localizationComparator.ts Union-key comparator · aiBatchTranslation.ts AI translation and batch execution
Components 20
React renderer
Unprivileged UI and client-side orchestration.
- App coordinator · Coordinates selection, edits, translations, review, and refresh.
src/App.tsx - Localization tree
src/components/localization/LocalizationTree.tsx - Localization summary
src/components/localization/LocalizationSummary.tsx - Translation review modals · Confirms single and batch translation proposals.
src/components/localization/AiTranslationConfirmModal.tsx - Add missing keys
src/components/localization/AddMissingKeysModal.tsx - Settings modal · Configures engine, provider, credentials, endpoint, and review policy.
src/components/settings/SettingsModal.tsx
Localization analysis
Comparison and inspection pipeline.
- Localization domain types
src/types/localization.ts - JSON parser · Builds usable localization key representations.
src/services/localizationParser.ts - Union-key comparator · Separates missing paths from present empty strings.
src/services/localizationComparator.ts - Tree and missing navigation · Supports hierarchy inspection and unresolved-item traversal.
src/services/localizationTree.ts - Localization writer · Reconstructs and formats JSON for atomic persistence.
src/services/localizationWriter.ts
Translation workflow
Planning, validation, policy, and provider selection.
- AI translation and batch execution · Runs single and batch requests with retry, backoff, and partial-failure handling.
src/services/aiBatchTranslation.ts - Batch planner · Groups by language pair/file and chunks or splits oversized work.
src/services/aiBatchPlanner.ts - Response validator · Preserves placeholders, syntax, escapes, and markup.
src/services/aiResponseValidator.ts - AI edit policy · Decides whether validated proposals need approval.
src/services/aiEditPolicy.ts - Provider registries · Contains AI and free-provider presets.
src/services/aiProviderRegistry.ts
Electron main process
Privileged filesystem and network boundary.
- Typed preload bridge · Exposes constrained window.electronAPI to the renderer.
electron/preload/index.ts - Main process services · Owns windows, filesystem access, atomic writes, and provider requests.
electron/main/index.ts - Translation providers · Cloud AI, Ollama, LibreTranslate, and MyMemory.
- Localization JSON files
Connections 24
- App coordinator → JSON parser: parses selected files
- JSON parser → Union-key comparator: key representations
- Localization domain types → JSON parser: defines structures
- Localization domain types → Union-key comparator: defines comparison state
- Union-key comparator → Tree and missing navigation: comparison state
- Tree and missing navigation → Localization tree: hierarchy and navigation
- Union-key comparator → Localization summary: missing and empty status
- Settings modal → Provider registries: selects engine and preset
- App coordinator → Batch planner: translation work
- Batch planner → AI translation and batch execution: grouped chunks
- Provider registries → AI translation and batch execution: provider configuration
- AI translation and batch execution → Response validator: generated proposals
- Response validator → AI edit policy: validated results
- AI edit policy → Translation review modals: approval required
- Translation review modals → Localization writer: approved translations
- Add missing keys → Localization writer: insert absent keys
- App coordinator → Typed preload bridge: typed IPC calls
- Localization writer → Typed preload bridge: write request
- AI translation and batch execution → Typed preload bridge: translation request
- Typed preload bridge → Main process services: constrained IPC
- Main process services → Localization JSON files: read and atomic write
- Main process services → Translation providers: provider network requests
- Localization JSON files → JSON parser: selected JSON content
- Main process services → App coordinator: write completion triggers refresh