import json

# Load English source
with open('/working/aisbf/static/i18n/en.json') as f:
    en = json.load(f)

# Load target languages
with open('/working/aisbf/static/i18n/cs.json') as f:
    cs = json.load(f)
with open('/working/aisbf/static/i18n/el.json') as f:
    el = json.load(f)
with open('/working/aisbf/static/i18n/hu.json') as f:
    hu = json.load(f)

# All high-priority keys from TRANSLATIONS_TODO.md
all_hp_keys = [
    'providers.provider_key_label',
    'providers.provider_count_singular',
    'providers.provider_count_plural',
    'providers.search_models_title',
    'providers.result_count',
    'providers.kiro_auth_title',
    'providers.kiro_opt1',
    'providers.kiro_opt2',
    'providers.kiro_opt3',
    'providers.kiro_opt4',
    'providers.kiro_aws_region',
    'providers.kiro_sqlite_path',
    'providers.kiro_refresh_token',
    'providers.kiro_profile_arn',
    'providers.kiro_client_id',
    'providers.kiro_client_secret',
    'providers.kiro_upload_creds',
    'providers.kiro_upload_sqlite',
    'providers.kilo_opt1',
    'providers.kilo_opt2',
    'providers.qwen_opt2_discontinued',
    'providers.kiro_auth_section',
    'providers.kilo_auth_section',
    'providers.workspace_id',
    'providers.oauth2_issuer_url',
    'providers.pricing_section',
    'providers.subscription_based',
    'providers.price_prompt',
    'providers.price_completion',
    'providers.default_rate_limit_tpm',
    'providers.default_rate_limit_tph',
    'providers.default_rate_limit_tpd',
    'providers.default_condense_context',
    'providers.default_condense_method',
    'providers.nsfw',
    'providers.privacy',
    'providers.native_caching_section',
    'providers.enable_native_caching',
    'providers.cache_ttl',
    'providers.min_cacheable_tokens',
    'providers.prompt_cache_key',
    'providers.model_filter',
    'providers.model_rate_limit_tpm',
    'providers.model_rate_limit_tph',
    'providers.model_rate_limit_tpd',
    'providers.model_condense_context',
    'providers.model_condense_method',
    'providers.remove_provider_title',
    'providers.remove_model_title',
    'providers.missing_key',
    'providers.missing_key_title',
    'providers.duplicate_key',
    'providers.duplicate_key_title',
    'providers.models_found',
    'providers.not_authenticated',
    'providers.uploading_file',
    'providers.uploading_cli',
    'providers.cli_creds_saved',
    'providers.upload_failed',
    'providers.fetching_models',
    'providers.checking_auth',
    'providers.auth_valid',
    'providers.auth_failed',
    'providers.auth_error',
    'providers.auth_success',
    'providers.auth_timeout',
    'providers.auth_denied',
    'providers.auth_expired',
    'providers.auth_start_failed',
    'providers.auth_error_completing',
    'providers.auth_generic_error',
    'providers.remove_provider_confirm',
    'providers.remove_model_confirm',
    'providers.error_saving',
    'providers.models_fetch_error',
    'providers.standard_config',
    'rotations.search_models_title',
    'rotations.result_count',
    'rotations.copy_title',
    'rotations.add_title',
    'rotations.key_exists',
    'rotations.key_exists_title',
    'rotations.invalid_key_title',
    'rotations.remove_title',
    'rotations.remove_provider_title',
    'rotations.remove_model_title',
    'rotations.copy_prompt',
    'rotations.add_prompt',
    'rotations.key_different',
    'rotations.remove_confirm',
    'rotations.remove_provider_confirm',
    'rotations.remove_model_confirm',
    'rotations.error_saving',
    'autoselect.copy_title',
    'autoselect.add_title',
    'autoselect.key_exists',
    'autoselect.key_exists_title',
    'autoselect.invalid_key_title',
    'autoselect.remove_title',
    'autoselect.remove_model_title',
    'autoselect.result_count',
    'autoselect.models_found',
    'autoselect.copy_prompt',
    'autoselect.add_prompt',
    'autoselect.key_different',
    'autoselect.remove_confirm',
    'autoselect.remove_model_confirm',
    'autoselect.error_saving',
    'wallet_page.currency',
    'wallet_page.wallet_id',
    'wallet_page.charged_to_card',
    'wallet_page.invalid_amount',
    'wallet_page.invalid_amount_title',
    'rate_limits_page.refresh',
    'rate_limits_page.provider_label',
    'rate_limits_page.enabled',
    'rate_limits_page.current_rate_limit',
    'rate_limits_page.base_rate_limit',
    'rate_limits_page.total_429',
    'rate_limits_page.total_requests',
    'rate_limits_page.consecutive_429',
    'rate_limits_page.recent_429',
    'rate_limits_page.last_429',
    'rate_limits_page.never',
    'rate_limits_page.seconds',
    'rate_limits_page.yes',
    'rate_limits_page.no',
    'rate_limits_page.reset_all_title',
    'rate_limits_page.analytics',
    'rate_limits_page.response_cache',
    'rate_limits_page.rate_limits',
    'rate_limits_page.reset_confirm',
    'rate_limits_page.reset_confirm_title',
    'rate_limits_page.reset_all_confirm',
    'rate_limits_page.reset_all_success',
    'login_page.remember_me',
    'signup_page.username_hint',
    'signup_page.email_hint',
    'signup_page.password_hint',
    'forgot_page.intro',
    'forgot_page.sent',
    'reset_page.intro',
    'reset_page.password_hint',
    'reset_page.success',
    'reset_page.go_to_login',
    'reset_page.invalid_token',
    'reset_page.request_new',
    'profile_page.display_name_hint',
    'profile_page.no_email',
    'profile_page.add_email',
    'profile_page.change_email',
    'profile_page.email_requires_verify',
    'profile_page.upload_image',
    'profile_page.upload_hint',
    'profile_page.danger_zone',
    'profile_page.danger_zone_desc',
    'profile_page.delete_account',
    'profile_page.uploading',
    'profile_page.upload_pct',
    'profile_page.upload_success',
    'profile_page.upload_too_large',
    'profile_page.upload_invalid_type',
    'profile_page.upload_failed',
    'email_page.password_hint',
    'delete_page.danger_zone',
    'delete_page.danger_zone_desc',
    'delete_page.will_delete',
    'delete_page.item_account',
    'delete_page.item_providers',
    'delete_page.item_rotations',
    'delete_page.item_history',
    'delete_page.item_tokens',
    'delete_page.sub_warning_title',
    'delete_page.sub_warning_desc',
    'delete_page.sub_item_cancel',
    'delete_page.sub_item_access',
    'delete_page.sub_item_refund',
    'delete_page.sub_consider',
    'delete_page.type_delete_confirm',
    'delete_page.final_confirm',
    'tokens_page.new_token',
    'tokens_page.your_tokens',
    'tokens_page.description',
    'tokens_page.description_optional',
    'tokens_page.description_placeholder',
    'tokens_page.scope_api',
    'tokens_page.scope_api_hint',
    'tokens_page.scope_mcp',
    'tokens_page.scope_mcp_hint',
    'tokens_page.scope_both',
    'tokens_page.create_btn',
    'tokens_page.token_created',
    'tokens_page.copy_now_warn',
    'tokens_page.done',
    'tokens_page.how_to_use',
    'tokens_page.auth_header_desc',
    'tokens_page.token_scopes',
    'tokens_page.scope_api_access',
    'tokens_page.scope_mcp_access',
    'tokens_page.scope_both_access',
    'tokens_page.available_endpoints',
    'tokens_page.col_method',
    'tokens_page.col_endpoint',
    'tokens_page.col_scope',
    'tokens_page.col_description',
    'tokens_page.ep_list_models',
    'tokens_page.ep_list_providers',
    'tokens_page.ep_list_rotations',
    'tokens_page.ep_list_autoselects',
    'tokens_page.ep_chat',
    'tokens_page.ep_mcp_list',
    'tokens_page.ep_mcp_call',
    'tokens_page.example_commands',
    'tokens_page.active',
    'tokens_page.inactive',
    'tokens_page.created',
    'tokens_page.last_used',
    'tokens_page.unnamed_token',
    'tokens_page.delete_confirm',
    'tokens_page.delete_token',
    'billing_page.wallet_balance',
    'billing_page.wallet_desc',
    'billing_page.manage_wallet',
    'billing_page.no_payment_methods',
    'billing_page.no_payment_methods_desc',
    'billing_page.add_credit_card',
    'billing_page.top_up_wallet',
    'billing_page.set_default',
    'billing_page.default_label',
    'billing_page.billing_history',
    'billing_page.no_history',
    'billing_page.no_history_desc',
    'billing_page.no_history_upgrade',
    'billing_page.view_plans',
    'billing_page.plan_payment',
    'billing_page.col_date',
    'billing_page.col_description',
    'billing_page.col_amount',
    'billing_page.col_method',
    'billing_page.col_status',
    'billing_page.col_actions',
    'billing_page.status_completed',
    'billing_page.status_pending',
    'billing_page.status_failed',
    'billing_page.status_refunded',
    'billing_page.invoice',
    'billing_page.prev',
    'billing_page.next',
    'user_overview.stat_total_tokens',
    'user_overview.stat_requests_today',
    'user_overview.stat_active_providers',
    'user_overview.stat_active_rotations',
    'user_overview.quick_actions',
    'user_overview.subscription',
    'user_overview.manage',
    'user_overview.add_payment_method',
    'user_overview.unlock_more_power',
    'user_overview.upgrade_plan',
    'user_overview.higher_plans',
    'user_overview.upgrade_to',
    'user_overview.api_endpoints',
    'user_overview.show_hide',
    'user_overview.auth_header_desc',
    'user_overview.ep_models',
    'user_overview.ep_list_models',
    'user_overview.ep_providers',
    'user_overview.ep_list_providers',
    'user_overview.ep_rotations_autoselect',
    'user_overview.ep_list_rotations',
    'user_overview.ep_list_autoselects',
    'user_overview.ep_chat',
    'user_overview.ep_chat_desc',
    'user_overview.ep_mcp',
    'user_overview.ep_mcp_list',
    'user_overview.ep_mcp_call',
    'user_overview.ep_model_formats',
    'user_overview.admin_access',
    'user_overview.admin_access_desc',
    'user_overview.token_required',
    'user_overview.manage_tokens',
    'usage_page.manage_subscription',
    'usage_page.current_plan',
    'usage_page.activity_quotas',
    'usage_page.activity_quotas_desc',
    'usage_page.config_limits',
    'usage_page.config_limits_desc',
    'usage_page.requests_today',
    'usage_page.resets_midnight',
    'usage_page.resets_in',
    'usage_page.requests_month',
    'usage_page.resets_on_1st',
    'usage_page.resets_in_days',
    'usage_page.resets_in_days_plural',
    'usage_page.tokens_24h',
    'usage_page.tokens_combined',
    'usage_page.tokens_used',
    'usage_page.unlimited',
    'usage_page.quota_reached',
    'usage_page.remaining',
    'usage_page.ai_providers',
    'usage_page.ai_providers_desc',
    'usage_page.rotations',
    'usage_page.rotations_desc',
    'usage_page.autoselections',
    'usage_page.autoselections_desc',
    'usage_page.unlimited_slots',
    'usage_page.pct_used_slots_free',
    'usage_page.pct_used_slots_free_plural',
    'usage_page.need_higher_limits',
    'usage_page.upgrade_desc',
    'usage_page.view_plans',
    'prompts_page.select_file',
    'prompts_page.content_hint',
    'prompts_page.reset_confirm',
    'prompts_page.reset_confirm_title',
    'subscription_page.title',
    'subscription_page.current_plan',
    'subscription_page.free_tier',
    'subscription_page.no_description',
    'subscription_page.per_month',
    'subscription_page.per_year',
    'subscription_page.or_yearly',
    'subscription_page.change_plan',
    'subscription_page.requests_per_day',
    'subscription_page.requests_per_month',
    'subscription_page.providers',
    'subscription_page.rotations',
    'subscription_page.subscription_status',
    'subscription_page.renews',
    'subscription_page.cancel_subscription',
    'subscription_page.quick_actions',
    'subscription_page.billing_payments',
    'subscription_page.billing_payments_desc',
    'subscription_page.upgrade_plan',
    'subscription_page.upgrade_plan_desc',
    'subscription_page.edit_profile',
    'subscription_page.edit_profile_desc',
    'subscription_page.change_password',
    'subscription_page.change_password_desc',
    'subscription_page.no_payment_methods',
    'subscription_page.no_payment_methods_desc',
    'subscription_page.go_to_billing',
    'user_providers_page.title',
    'user_providers_page.add_new',
    'user_rotations_page.title',
    'user_rotations_page.add_rotation',
    'user_rotations_page.save_config',
    'user_rotations_page.cancel',
    'user_autoselects_page.title',
    'user_autoselects_page.add_autoselect',
    'user_autoselects_page.save_config',
    'user_autoselects_page.cancel',
]

# Exclude keys ending in _hint or _desc (per instructions)
translate_keys = [k for k in all_hp_keys if not (k.endswith('_hint') or k.endswith('_desc'))]
print(f"Total high-priority keys to translate (excluding _hint/_desc): {len(translate_keys)}")

def get_nested(d, key):
    parts = key.split('.')
    c = d
    for p in parts:
        if p not in c:
            return None
        c = c[p]
    return c

# Find keys that need translation (None or equals English)
need_cs = {}
need_el = {}
need_hu = {}

for key in translate_keys:
    en_val = get_nested(en, key)
    if en_val is None:
        continue
    
    cs_val = get_nested(cs, key)
    el_val = get_nested(el, key)
    hu_val = get_nested(hu, key)
    
    # Check if needs translation (None or equals English)
    if cs_val is None or (isinstance(cs_val, str) and cs_val == en_val):
        need_cs[key] = en_val
    if el_val is None or (isinstance(el_val, str) and el_val == en_val):
        need_el[key] = en_val
    if hu_val is None or (isinstance(hu_val, str) and hu_val == en_val):
        need_hu[key] = en_val

print(f"Czech keys needing translation: {len(need_cs)}")
print(f"Greek keys needing translation: {len(need_el)}")
print(f"Hungarian keys needing translation: {len(need_hu)}")

# Show some examples
print("\nSample Czech keys to translate:")
for k in list(need_cs.keys())[:5]:
    print(f"  {k}: {need_cs[k]}")
