From b8cab29ed2ae7219cd1b377e84f25413b4dc225e Mon Sep 17 00:00:00 2001 From: AutonetSellCar Deploy Date: Sat, 3 Jan 2026 20:53:14 +0900 Subject: [PATCH] Add 'Seed Defaults' button to load all predefined translations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add /translations/seed-all-defaults API endpoint - Loads all DEFAULT_TRANSLATIONS (makers, models, colors, fuels, transmissions) - Includes 100+ predefined translations (Mohave, Sonata, colors, etc.) - Add 'Seed Defaults' button to admin translations page 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- backend/app/api/translations.py | 41 ++++++++++++++++++++ frontend/src/app/admin/translations/page.tsx | 23 +++++++++++ frontend/src/lib/api.ts | 5 +++ 3 files changed, 69 insertions(+) diff --git a/backend/app/api/translations.py b/backend/app/api/translations.py index dba42a1..708f254 100644 --- a/backend/app/api/translations.py +++ b/backend/app/api/translations.py @@ -637,6 +637,47 @@ def fill_default_translations(db: Session = Depends(get_db)): return {"message": f"Updated {updated_count} translations with default values"} +@router.post("/seed-all-defaults") +def seed_all_default_translations(db: Session = Depends(get_db)): + """ + Seed ALL translations from the DEFAULT_TRANSLATIONS dictionary into the database. + This pre-populates translations for all known terms, not just those in the cars table. + """ + added_count = 0 + skipped_count = 0 + + for category, terms in DEFAULT_TRANSLATIONS.items(): + for korean_text, translations in terms.items(): + # Check if already exists + existing = db.query(Translation).filter( + Translation.source_text == korean_text, + Translation.category == category + ).first() + + if existing: + skipped_count += 1 + continue + + trans = Translation( + source_text=korean_text, + category=category, + text_en=translations.get("en", korean_text), + text_mn=translations.get("mn", korean_text), + text_ru=translations.get("ru", korean_text) + ) + db.add(trans) + added_count += 1 + + db.commit() + + return { + "message": f"Seeded {added_count} translations from default dictionary (skipped {skipped_count} existing)", + "added": added_count, + "skipped": skipped_count, + "categories": list(DEFAULT_TRANSLATIONS.keys()) + } + + # AI Auto-Translation Service import httpx import json diff --git a/frontend/src/app/admin/translations/page.tsx b/frontend/src/app/admin/translations/page.tsx index c11fae1..35c6f8f 100644 --- a/frontend/src/app/admin/translations/page.tsx +++ b/frontend/src/app/admin/translations/page.tsx @@ -115,6 +115,18 @@ export default function TranslationsPage() { } }; + const handleSeedAllDefaults = async () => { + try { + const result = await translationsApi.seedAllDefaults(); + alert(`${result.message}\n\nCategories: ${result.categories.join(', ')}`); + loadTranslations(); + loadStats(); + } catch (err) { + console.error('Failed to seed defaults:', err); + alert('Failed to seed default translations'); + } + }; + const handleAutoTranslate = async (translation: Translation) => { setTranslatingId(translation.id); try { @@ -217,9 +229,20 @@ export default function TranslationsPage() {

Translations Management

+