"""
VenvStudio - Internationalization (i18n) System
Supports: English, Türkçe, Deutsch, Français, Español, Português, Русский, 中文, 日本語, 한국어, العربية
"""

_current_lang = "en"
_translations = {}


def set_language(lang_code: str):
    global _current_lang
    _current_lang = lang_code


def get_language() -> str:
    return _current_lang


def tr(key: str) -> str:
    """Translate a key to the current language. Falls back to English."""
    lang_dict = TRANSLATIONS.get(_current_lang, TRANSLATIONS["en"])
    return lang_dict.get(key, TRANSLATIONS["en"].get(key, key))


TRANSLATIONS = {
    "en": {
        # Main Window
        "app_title": "VenvStudio",
        "environments": "Environments",
        "packages": "Packages",
        "settings": "Settings",
        "virtual_environments": "Virtual Environments",
        "refresh": "Refresh",
        "new_environment": "New Environment",
        "manage_packages": "Manage Packages",
        "open_terminal": "Open Terminal",
        "clone": "Clone",
        "rename": "Rename",
        "delete": "Delete",
        "ready": "Ready",
        "loading_environments": "Loading environments, please wait...",
        "found_n_environments": "Found {n} environment(s)",
        "selected": "Selected: {name}",
        "no_environments": "No environments found",

        # Menu
        "file": "&File",
        "view": "&View",
        "help": "&Help",
        "quit": "&Quit",
        "about": "&About",
        "dark_theme": "Dark Theme",
        "light_theme": "Light Theme",

        # Env Dialog
        "create_new_environment": "Create New Environment",
        "setup_fresh_venv": "Set up a fresh Python virtual environment",
        "env_settings": "Environment Settings",
        "name": "Name:",
        "location": "Location:",
        "python": "Python:",
        "system_default": "System Default",
        "options": "Options",
        "upgrade_pip": "Upgrade pip after creation",
        "include_system_packages": "Include system site-packages",
        "progress": "Progress",
        "cancel": "Cancel",
        "create_environment": "Create Environment",
        "creating": "Creating...",
        "success": "Success",
        "error": "Error",
        "warning": "Warning",

        # Package Panel
        "installed": "Installed",
        "catalog": "Catalog",
        "presets": "Presets",
        "manual_install": "Manual Install",
        "select_environment": "-- Select Environment --",
        "environment": "Environment:",
        "filter_installed": "Filter installed packages...",
        "uninstall_selected": "Uninstall Selected",
        "packages_count": "{n} packages",
        "export_requirements": "Export requirements.txt",
        "import_requirements": "Import requirements.txt",
        "category": "Category:",
        "all_categories": "All Categories",
        "apply_changes": "Apply Changes",
        "no_changes": "No Changes",
        "no_changes_detected": "No changes detected.",
        "confirm_installation": "Confirm Installation",
        "install_packages_q": "Install the following {n} package(s)?",
        "confirm_uninstall": "Confirm Uninstall",
        "uninstall_packages_q": "Uninstall {n} package(s)?",
        "no_packages_selected": "No packages selected for uninstall.",
        "operation_completed": "Operation completed successfully",
        "operation_failed": "Operation failed",
        "operation_cancelled": "Operation cancelled",
        "package_not_found": "Package Not Found",
        "package_not_found_msg": "One or more packages could not be found on PyPI.\n\nPlease check the package names and try again.",
        "cancel_operation": "Cancel Operation",
        "cancel_operation_q": "Are you sure you want to cancel the current operation?",
        "search_catalog": "Search catalog...",
        "install": "Install",
        "copy_command": "Copy Command",
        "command_copied": "Command copied to clipboard!",

        # Settings
        "settings_title": "Settings",
        "customize_venvstudio": "Customize VenvStudio to your preferences",
        "appearance": "Appearance",
        "theme": "Theme:",
        "dark": "Dark",
        "light": "Light",
        "font": "Font:",
        "font_size": "Font Size:",
        "language": "Language",
        "interface_language": "Interface Language:",
        "language_note": "Enable the checkbox to change language. App will restart.",
        "python_versions": "Python Versions",
        "python_info": "System Python installations detected automatically. You can also add custom paths.",
        "scan_system": "Scan System",
        "add_custom_path": "Add Custom Path",
        "remove_selected": "Remove Selected",
        "default_python": "Default Python for new environments:",
        "paths": "Paths",
        "venv_base_dir": "Environments Folder:",
        "browse": "Browse",
        "general": "General",
        "auto_upgrade_pip": "Auto-upgrade pip when creating new environments",
        "confirm_delete": "Ask for confirmation before deleting environments",
        "show_hidden_packages": "Show hidden/system packages in package list",
        "check_updates": "Check for VenvStudio updates on startup",
        "remember_window": "Remember window size and position",
        "default_terminal": "Default Terminal:",
        "save_settings": "Save Settings",
        "reset_defaults": "Reset All to Defaults",
        "settings_saved": "Settings saved successfully!",
        "reset_confirm": "Are you sure you want to reset all settings to defaults?",
        "about_title": "About",

        # Delete / Clone / Rename
        "delete_environment": "Delete Environment",
        "delete_confirm": "Are you sure you want to delete '{name}'?\n\nThis will permanently remove the environment and all installed packages.",
        "deleting": "Deleting '{name}'...",
        "clone_environment": "Clone Environment",
        "clone_name_prompt": "Enter name for the clone of '{name}':",
        "cloning": "Cloning '{source}' → '{target}'...",
        "rename_environment": "Rename Environment",
        "rename_prompt": "Enter new name for '{name}':\n\n(Creates a new environment with same packages and removes the old one.)",
        "renaming": "Renaming '{old}' → '{new}'...",
        "invalid_characters": "Name contains invalid characters.",

        # App Launcher
        "app_launcher": "Launch",
        "launch_app": "Launch {app}",
        "create_shortcut": "Create Desktop Shortcut",
        "shortcut_created": "Desktop shortcut created for {app}!",
        "app_not_installed": "{app} is not installed in this environment.",

        # Updates
        "updates": "Updates",
        "check_outdated": "Check for Updates",
        "update_all": "Update All",
        "update_selected": "Update Selected",
        "no_updates": "All packages are up to date.",
        "outdated_packages": "{n} package(s) have updates available.",
    },

    "tr": {
        "app_title": "VenvStudio",
        "environments": "Ortamlar",
        "packages": "Paketler",
        "settings": "Ayarlar",
        "virtual_environments": "Sanal Ortamlar",
        "refresh": "Yenile",
        "new_environment": "Yeni Ortam",
        "manage_packages": "Paketleri Yönet",
        "open_terminal": "Terminal Aç",
        "clone": "Kopyala",
        "rename": "Yeniden Adlandır",
        "delete": "Sil",
        "ready": "Hazır",
        "loading_environments": "Ortamlar yükleniyor, lütfen bekleyin...",
        "found_n_environments": "{n} ortam bulundu",
        "selected": "Seçili: {name}",
        "no_environments": "Ortam bulunamadı",
        "file": "&Dosya",
        "view": "&Görünüm",
        "help": "&Yardım",
        "quit": "&Çıkış",
        "about": "&Hakkında",
        "dark_theme": "Koyu Tema",
        "light_theme": "Açık Tema",
        "create_new_environment": "Yeni Ortam Oluştur",
        "setup_fresh_venv": "Yeni bir Python sanal ortamı oluşturun",
        "env_settings": "Ortam Ayarları",
        "name": "Ad:",
        "location": "Konum:",
        "python": "Python:",
        "system_default": "Sistem Varsayılanı",
        "options": "Seçenekler",
        "upgrade_pip": "Oluşturma sonrası pip'i güncelle",
        "include_system_packages": "Sistem paketlerini dahil et",
        "progress": "İlerleme",
        "cancel": "İptal",
        "create_environment": "Ortam Oluştur",
        "creating": "Oluşturuluyor...",
        "success": "Başarılı",
        "error": "Hata",
        "warning": "Uyarı",
        "installed": "Yüklü",
        "catalog": "Katalog",
        "presets": "Hazır Paketler",
        "manual_install": "Manuel Yükleme",
        "select_environment": "-- Ortam Seçin --",
        "environment": "Ortam:",
        "filter_installed": "Yüklü paketleri filtrele...",
        "uninstall_selected": "Seçilenleri Kaldır",
        "packages_count": "{n} paket",
        "export_requirements": "requirements.txt Dışa Aktar",
        "import_requirements": "requirements.txt İçe Aktar",
        "category": "Kategori:",
        "all_categories": "Tüm Kategoriler",
        "apply_changes": "Değişiklikleri Uygula",
        "no_changes": "Değişiklik Yok",
        "no_changes_detected": "Herhangi bir değişiklik algılanmadı.",
        "confirm_installation": "Yüklemeyi Onayla",
        "install_packages_q": "Aşağıdaki {n} paket(ler) yüklensin mi?",
        "confirm_uninstall": "Kaldırmayı Onayla",
        "uninstall_packages_q": "{n} paket kaldırılsın mı?",
        "no_packages_selected": "Kaldırılacak paket seçilmedi.",
        "operation_completed": "İşlem başarıyla tamamlandı",
        "operation_failed": "İşlem başarısız oldu",
        "operation_cancelled": "İşlem iptal edildi",
        "package_not_found": "Paket Bulunamadı",
        "package_not_found_msg": "Bir veya daha fazla paket PyPI'da bulunamadı.\n\nPaket adlarını kontrol edip tekrar deneyin.",
        "cancel_operation": "İşlemi İptal Et",
        "cancel_operation_q": "Devam eden işlemi iptal etmek istediğinizden emin misiniz?",
        "search_catalog": "Katalogda ara...",
        "install": "Yükle",
        "copy_command": "Komutu Kopyala",
        "command_copied": "Komut panoya kopyalandı!",
        "settings_title": "Ayarlar",
        "customize_venvstudio": "VenvStudio'yu tercihlerinize göre özelleştirin",
        "appearance": "Görünüm",
        "theme": "Tema:",
        "dark": "Koyu",
        "light": "Açık",
        "font": "Yazı Tipi:",
        "font_size": "Yazı Boyutu:",
        "language": "Dil",
        "interface_language": "Arayüz Dili:",
        "language_note": "Dili değiştirmek için onay kutusunu etkinleştirin. Uygulama yeniden başlar.",
        "python_versions": "Python Sürümleri",
        "python_info": "Sistem Python kurulumları otomatik algılanır. Özel yollar da ekleyebilirsiniz.",
        "scan_system": "Sistemi Tara",
        "add_custom_path": "Özel Yol Ekle",
        "remove_selected": "Seçileni Kaldır",
        "default_python": "Yeni ortamlar için varsayılan Python:",
        "paths": "Yollar",
        "venv_base_dir": "Ortamlar Klasörü:",
        "browse": "Gözat",
        "general": "Genel",
        "auto_upgrade_pip": "Yeni ortam oluşturulurken pip'i otomatik güncelle",
        "confirm_delete": "Ortam silmeden önce onay iste",
        "show_hidden_packages": "Gizli/sistem paketlerini göster",
        "check_updates": "Başlangıçta VenvStudio güncellemelerini kontrol et",
        "remember_window": "Pencere boyutunu ve konumunu hatırla",
        "default_terminal": "Varsayılan Terminal:",
        "save_settings": "Ayarları Kaydet",
        "reset_defaults": "Varsayılanlara Sıfırla",
        "settings_saved": "Ayarlar başarıyla kaydedildi!",
        "reset_confirm": "Tüm ayarları varsayılanlara sıfırlamak istediğinizden emin misiniz?",
        "about_title": "Hakkında",
        "delete_environment": "Ortamı Sil",
        "delete_confirm": "'{name}' ortamını silmek istediğinizden emin misiniz?\n\nBu işlem ortamı ve tüm yüklü paketleri kalıcı olarak kaldıracaktır.",
        "deleting": "'{name}' siliniyor...",
        "clone_environment": "Ortamı Kopyala",
        "clone_name_prompt": "'{name}' kopyası için bir ad girin:",
        "cloning": "'{source}' → '{target}' kopyalanıyor...",
        "rename_environment": "Ortamı Yeniden Adlandır",
        "rename_prompt": "'{name}' için yeni ad girin:\n\n(Aynı paketlerle yeni bir ortam oluşturur ve eskisini siler.)",
        "renaming": "'{old}' → '{new}' yeniden adlandırılıyor...",
        "invalid_characters": "Ad geçersiz karakterler içeriyor.",
        "app_launcher": "Başlat",
        "launch_app": "{app} Başlat",
        "create_shortcut": "Masaüstü Kısayolu Oluştur",
        "shortcut_created": "{app} için masaüstü kısayolu oluşturuldu!",
        "app_not_installed": "{app} bu ortamda yüklü değil.",
        "updates": "Güncellemeler",
        "check_outdated": "Güncellemeleri Kontrol Et",
        "update_all": "Tümünü Güncelle",
        "update_selected": "Seçilenleri Güncelle",
        "no_updates": "Tüm paketler güncel.",
        "outdated_packages": "{n} paketin güncellemesi mevcut.",
    },

    "de": {
        "app_title": "VenvStudio",
        "environments": "Umgebungen",
        "packages": "Pakete",
        "settings": "Einstellungen",
        "virtual_environments": "Virtuelle Umgebungen",
        "refresh": "Aktualisieren",
        "new_environment": "Neue Umgebung",
        "manage_packages": "Pakete verwalten",
        "open_terminal": "Terminal öffnen",
        "clone": "Klonen",
        "rename": "Umbenennen",
        "delete": "Löschen",
        "ready": "Bereit",
        "loading_environments": "Umgebungen werden geladen, bitte warten...",
        "found_n_environments": "{n} Umgebung(en) gefunden",
        "selected": "Ausgewählt: {name}",
        "file": "&Datei",
        "view": "&Ansicht",
        "help": "&Hilfe",
        "quit": "&Beenden",
        "about": "Ü&ber",
        "dark_theme": "Dunkles Thema",
        "light_theme": "Helles Thema",
        "create_new_environment": "Neue Umgebung erstellen",
        "name": "Name:",
        "location": "Speicherort:",
        "cancel": "Abbrechen",
        "create_environment": "Umgebung erstellen",
        "success": "Erfolg",
        "error": "Fehler",
        "warning": "Warnung",
        "installed": "Installiert",
        "catalog": "Katalog",
        "presets": "Voreinstellungen",
        "manual_install": "Manuelle Installation",
        "select_environment": "-- Umgebung auswählen --",
        "apply_changes": "Änderungen übernehmen",
        "save_settings": "Einstellungen speichern",
        "settings_saved": "Einstellungen erfolgreich gespeichert!",
        "delete_environment": "Umgebung löschen",
        "appearance": "Darstellung",
        "theme": "Thema:",
        "font": "Schriftart:",
        "font_size": "Schriftgröße:",
        "language": "Sprache",
        "general": "Allgemein",
        "default_terminal": "Standard-Terminal:",
    },

    "fr": {
        "app_title": "VenvStudio",
        "environments": "Environnements",
        "packages": "Paquets",
        "settings": "Paramètres",
        "virtual_environments": "Environnements virtuels",
        "refresh": "Actualiser",
        "new_environment": "Nouvel environnement",
        "manage_packages": "Gérer les paquets",
        "open_terminal": "Ouvrir le terminal",
        "clone": "Cloner",
        "rename": "Renommer",
        "delete": "Supprimer",
        "ready": "Prêt",
        "loading_environments": "Chargement des environnements, veuillez patienter...",
        "found_n_environments": "{n} environnement(s) trouvé(s)",
        "file": "&Fichier",
        "view": "&Affichage",
        "help": "&Aide",
        "quit": "&Quitter",
        "about": "À &propos",
        "create_new_environment": "Créer un nouvel environnement",
        "name": "Nom :",
        "location": "Emplacement :",
        "cancel": "Annuler",
        "create_environment": "Créer l'environnement",
        "success": "Succès",
        "error": "Erreur",
        "installed": "Installés",
        "catalog": "Catalogue",
        "presets": "Préréglages",
        "manual_install": "Installation manuelle",
        "select_environment": "-- Sélectionner un environnement --",
        "apply_changes": "Appliquer les modifications",
        "save_settings": "Enregistrer les paramètres",
        "settings_saved": "Paramètres enregistrés avec succès !",
        "appearance": "Apparence",
        "theme": "Thème :",
        "language": "Langue",
        "general": "Général",
        "default_terminal": "Terminal par défaut :",
    },

    "es": {
        "app_title": "VenvStudio",
        "environments": "Entornos",
        "packages": "Paquetes",
        "settings": "Configuración",
        "virtual_environments": "Entornos virtuales",
        "refresh": "Actualizar",
        "new_environment": "Nuevo entorno",
        "manage_packages": "Gestionar paquetes",
        "open_terminal": "Abrir terminal",
        "clone": "Clonar",
        "rename": "Renombrar",
        "delete": "Eliminar",
        "ready": "Listo",
        "file": "&Archivo",
        "view": "&Ver",
        "help": "A&yuda",
        "quit": "&Salir",
        "about": "&Acerca de",
        "create_new_environment": "Crear nuevo entorno",
        "cancel": "Cancelar",
        "success": "Éxito",
        "error": "Error",
        "installed": "Instalados",
        "catalog": "Catálogo",
        "presets": "Preajustes",
        "manual_install": "Instalación manual",
        "apply_changes": "Aplicar cambios",
        "save_settings": "Guardar configuración",
        "appearance": "Apariencia",
        "theme": "Tema:",
        "language": "Idioma",
        "general": "General",
    },

    "pt": {
        "app_title": "VenvStudio",
        "environments": "Ambientes",
        "packages": "Pacotes",
        "settings": "Configurações",
        "virtual_environments": "Ambientes virtuais",
        "refresh": "Atualizar",
        "new_environment": "Novo ambiente",
        "open_terminal": "Abrir terminal",
        "clone": "Clonar",
        "rename": "Renomear",
        "delete": "Excluir",
        "file": "&Arquivo",
        "view": "&Exibir",
        "help": "A&juda",
        "quit": "&Sair",
        "cancel": "Cancelar",
        "success": "Sucesso",
        "error": "Erro",
        "installed": "Instalados",
        "catalog": "Catálogo",
        "presets": "Predefinições",
        "apply_changes": "Aplicar alterações",
        "save_settings": "Salvar configurações",
        "appearance": "Aparência",
        "language": "Idioma",
        "general": "Geral",
    },

    "ru": {
        "app_title": "VenvStudio",
        "environments": "Окружения",
        "packages": "Пакеты",
        "settings": "Настройки",
        "virtual_environments": "Виртуальные окружения",
        "refresh": "Обновить",
        "new_environment": "Новое окружение",
        "open_terminal": "Открыть терминал",
        "clone": "Клонировать",
        "rename": "Переименовать",
        "delete": "Удалить",
        "file": "&Файл",
        "view": "&Вид",
        "help": "&Справка",
        "quit": "&Выход",
        "cancel": "Отмена",
        "success": "Успех",
        "error": "Ошибка",
        "installed": "Установленные",
        "catalog": "Каталог",
        "presets": "Предустановки",
        "apply_changes": "Применить изменения",
        "save_settings": "Сохранить настройки",
        "appearance": "Оформление",
        "language": "Язык",
        "general": "Общие",
    },

    "zh": {
        "app_title": "VenvStudio",
        "environments": "环境",
        "packages": "包",
        "settings": "设置",
        "virtual_environments": "虚拟环境",
        "refresh": "刷新",
        "new_environment": "新建环境",
        "open_terminal": "打开终端",
        "clone": "克隆",
        "rename": "重命名",
        "delete": "删除",
        "file": "文件(&F)",
        "view": "视图(&V)",
        "help": "帮助(&H)",
        "quit": "退出(&Q)",
        "cancel": "取消",
        "success": "成功",
        "error": "错误",
        "installed": "已安装",
        "catalog": "目录",
        "presets": "预设",
        "apply_changes": "应用更改",
        "save_settings": "保存设置",
        "appearance": "外观",
        "language": "语言",
        "general": "通用",
    },

    "ja": {
        "app_title": "VenvStudio",
        "environments": "環境",
        "packages": "パッケージ",
        "settings": "設定",
        "virtual_environments": "仮想環境",
        "refresh": "更新",
        "new_environment": "新しい環境",
        "open_terminal": "ターミナルを開く",
        "clone": "クローン",
        "rename": "名前変更",
        "delete": "削除",
        "file": "ファイル(&F)",
        "view": "表示(&V)",
        "help": "ヘルプ(&H)",
        "quit": "終了(&Q)",
        "cancel": "キャンセル",
        "success": "成功",
        "error": "エラー",
        "installed": "インストール済み",
        "catalog": "カタログ",
        "presets": "プリセット",
        "apply_changes": "変更を適用",
        "save_settings": "設定を保存",
        "appearance": "外観",
        "language": "言語",
        "general": "一般",
    },

    "ko": {
        "app_title": "VenvStudio",
        "environments": "환경",
        "packages": "패키지",
        "settings": "설정",
        "virtual_environments": "가상 환경",
        "refresh": "새로고침",
        "new_environment": "새 환경",
        "open_terminal": "터미널 열기",
        "clone": "복제",
        "rename": "이름 변경",
        "delete": "삭제",
        "file": "파일(&F)",
        "view": "보기(&V)",
        "help": "도움말(&H)",
        "quit": "종료(&Q)",
        "cancel": "취소",
        "success": "성공",
        "error": "오류",
        "installed": "설치됨",
        "catalog": "카탈로그",
        "presets": "프리셋",
        "apply_changes": "변경 적용",
        "save_settings": "설정 저장",
        "appearance": "모양",
        "language": "언어",
        "general": "일반",
    },

    "ar": {
        "app_title": "VenvStudio",
        "environments": "البيئات",
        "packages": "الحزم",
        "settings": "الإعدادات",
        "virtual_environments": "البيئات الافتراضية",
        "refresh": "تحديث",
        "new_environment": "بيئة جديدة",
        "open_terminal": "فتح الطرفية",
        "clone": "نسخ",
        "rename": "إعادة تسمية",
        "delete": "حذف",
        "cancel": "إلغاء",
        "success": "نجاح",
        "error": "خطأ",
        "installed": "مثبت",
        "catalog": "الكتالوج",
        "presets": "الإعدادات المسبقة",
        "apply_changes": "تطبيق التغييرات",
        "save_settings": "حفظ الإعدادات",
        "appearance": "المظهر",
        "language": "اللغة",
        "general": "عام",
    },
}
