<?php
session_start();

$translations = [
    'en' => [
        'nav_home' => 'Home',
        'nav_market' => 'Markets',
        'nav_trade' => 'Trade',
        'nav_spot' => 'Spot',
        'nav_futures' => 'Futures',
        'nav_mining' => 'Mining',
        'nav_convert' => 'Convert',
        'nav_assets' => 'Assets',
        'nav_total_assets' => 'Total Assets',
        'nav_deposit' => 'Deposit',
        'nav_withdraw' => 'Withdraw',
        'nav_login' => 'Log In',
        'nav_register' => 'Sign Up',
        'nav_profile' => 'Profile',
        'nav_logout' => 'Log Out',
        'hero_title' => 'Buy, trade, and hold 350+ cryptocurrencies on NovaEx',
        'hero_subtitle' => 'Join the world\'s largest crypto exchange with the lowest fees and best security.',
        'btn_start' => 'Get Started',
        'btn_download' => 'Download App',
        'app_download' => 'APP Download',
        'download_qr_tip' => 'Download App & Get Up to 50 USDT',
        'market_trends' => 'Market Trends',
        'view_more_markets' => 'View More Markets',
        'why_choose_us' => 'Why Choose Us?',
        'secure_storage' => 'Secure Storage',
        'secure_storage_desc' => 'We store the vast majority of the digital assets in secure offline storage.',
        'protected_insurance' => 'Protected by Insurance',
        'protected_insurance_desc' => 'Cryptocurrency stored on our servers is covered by our insurance policy.',
        'industry_best_practices' => 'Industry Best Practices',
        'industry_best_practices_desc' => 'NovaEx supports a variety of the most popular digital currencies.',
        'platform_desc' => 'Our platform provides a seamless trading experience with advanced features and a robust infrastructure designed for both retail and institutional traders.',
        'partners' => 'Our Partners',
        'partners_subtitle' => 'Trusted by world-leading organizations and financial institutions.',
        'footer_desc' => 'NovaEx is a leading digital asset trading platform, providing secure and stable trading services for global users.',
        'about' => 'About',
        'about_us' => 'About Us',
        'careers' => 'Careers',
        'news' => 'News',
        'legal_privacy' => 'Legal & Privacy',
        'terms_service' => 'Terms of Service',
        'products' => 'Products',
        'spot_trading' => 'Spot Trading',
        'futures_trading' => 'Futures Trading',
        'flash_swap' => 'Flash Swap',
        'staking' => 'Staking',
        'asset_management' => 'Asset Management',
        'support' => 'Support',
        'help_center' => 'Help Center',
        'submit_request' => 'Submit a Request',
        'api_docs' => 'API Documentation',
        'fee_schedule' => 'Fee Schedule',
        'service_status' => 'Service Status',
        'all_rights_reserved' => 'ALL RIGHTS RESERVED.',
        'cookie_policy' => 'Cookie Policy',
        'security' => 'Security',
        'system_status_normal' => 'System Status: Normal',
        'personal_center' => 'Personal Center',
        'uid' => 'UID',
        'credit_score' => 'Credit Score',
        'kyc_status' => 'Identity Verification',
        'kyc_none' => 'Not Verified',
        'kyc_pending' => 'Pending Review',
        'kyc_approved' => 'Verified',
        'kyc_rejected' => 'Verification Failed',
        'kyc_submit' => 'Submit Verification',
        'total_balance' => 'Total Balance',
        'available_balance' => 'Available',
        'order_book' => 'Order Book',
        'trade_panel' => 'Trade Panel',
        'k_line' => 'K-Line',
        'open_orders' => 'Open Orders',
        'order_history' => 'Order History',
        'trade_history' => 'Trade History',
        'funds_flow' => 'Funds Flow',
        'current_positions' => 'Current Positions',
        'limit' => 'Limit',
        'market' => 'Market',
        'price' => 'Price',
        'amount' => 'Amount',
        'total' => 'Total',
        'buy' => 'Buy',
        'sell' => 'Sell',
        'leverage' => 'Leverage',
        'tp_sl' => 'TP/SL',
        'take_profit' => 'Take Profit',
        'stop_loss' => 'Stop Loss',
        'cost' => 'Cost',
        'open_long' => 'Open Long',
        'open_short' => 'Open Short',
        'security_settings' => 'Security Settings',
        'asset_details' => 'Asset Details',
        'transaction_records' => 'Transaction Records',
        'level' => 'Level',
        'crypto_markets' => 'Crypto Markets',
        '24h_volume' => '24h Volume',
        'fear_greed' => 'Fear & Greed Index',
        'btc_dominance' => 'BTC Dominance',
        'favorites' => 'Favorites',
        'all_crypto' => 'All Crypto',
        'asset' => 'Asset',
        '24h_high_low' => '24h High/Low',
        'deposit_assets' => 'Deposit Assets',
        'deposit_method_tip' => 'Select your preferred method to fund your account.',
        'fiat_deposit' => 'Fiat Deposit',
        'crypto_deposit' => 'Crypto Deposit',
        'bank_transfer' => 'Local Bank Transfer',
        'blockchain_transfer' => 'Blockchain Transfer',
        'support_20_global' => 'Support 20+ Global Currencies',
        'safe_compliant' => 'Safe & Compliant Channel',
        'fast_processing' => '24/7 Fast Processing',
        'no_service_fee' => 'No Service Fee',
        'select_currency' => 'Select Currency',
        'deposit_amount' => 'Deposit Amount',
        'matching_instructions' => 'Matching Instructions',
        'matching_tip' => 'Our intelligent matching system will pair you with a verified merchant. After confirming, you will receive the bank account details. Please complete the transfer within the time limit.',
        'match_now' => 'Match Merchant Now',
        'select_network' => 'Select Network',
        'get_address' => 'Get Deposit Address',
        'withdraw_assets' => 'Withdraw Assets',
        'withdraw_tip' => 'Securely withdraw USDT to your external wallet.',
        'withdraw_address' => 'Withdrawal Address',
        'trading_password' => 'Trading Password',
        'submit_withdrawal' => 'Submit Withdrawal',
        'withdrawal_tips' => 'Withdrawal Tips',
        'withdrawal_tip_1' => 'Double check the destination address. We cannot recover funds sent to wrong addresses.',
        'withdrawal_tip_2' => 'TRC20 withdrawals usually take 5-10 minutes to arrive.',
        'withdrawal_tip_3' => 'Withdrawals are processed manually for security audits during peak hours.',
        'withdrawal_tip_4' => 'Handling fee: 1 USDT per transaction.',
        'recent_history' => 'Recent History',
        'no_records' => 'No records found',
        'max' => 'MAX',
        'customer_service' => 'Online Support',
        'chat_welcome' => 'Hello! How can we help you today?',
        'type_message' => 'Type your message...',
        'matching_account' => 'Matching Payment Account...',
        'matching_desc' => 'Our system is matching a secure local account for your deposit. Please wait a moment.',
        'crypto' => 'Cryptocurrency',
        'search_market' => 'Search Market',
        'more_pairs' => 'More Pairs',
        'limit_order' => 'Limit',
        'market_order' => 'Market',
        'available' => 'Available',
        'buy_long' => 'Buy / Long',
        'sell_short' => 'Sell / Short',
        'open_position' => 'Open',
        'close_position' => 'Close',
        'cross' => 'Cross',
        'isolated' => 'Isolated',
        'positions' => 'Positions',
        'no_positions' => 'No positions found',
        'perpetual' => 'Perpetual',
        'delivery' => 'Delivery',
        'fee' => 'Fee',
        'max_open' => 'Max Open',
        'time' => 'Time',
        'pair' => 'Pair',
        'side' => 'Side',
        'filled' => 'Filled',
        'status' => 'Status',
        'load_more' => 'Load More',
    ],
    'zh' => [
        'nav_home' => '首页',
        'nav_market' => '行情',
        'nav_trade' => '交易',
        'nav_spot' => '现货交易',
        'nav_futures' => '合约交易',
        'nav_mining' => '挖矿',
        'nav_convert' => '闪兑',
        'nav_assets' => '资产',
        'nav_total_assets' => '总资产',
        'nav_deposit' => '充值',
        'nav_withdraw' => '提现',
        'nav_login' => '登录',
        'nav_register' => '注册',
        'nav_profile' => '个人中心',
        'nav_logout' => '退出登录',
        'hero_title' => '在 NovaEx 购买、交易和持有 350 多种加密货币',
        'hero_subtitle' => '加入全球最大的加密货币交易所，享受最低的费用和最好的安全性。',
        'btn_start' => '立即开始',
        'btn_download' => '下载应用',
        'app_download' => 'APP 下载',
        'download_qr_tip' => '下载应用并获得高达 50 USDT 的奖励',
        'market_trends' => '市场趋势',
        'view_more_markets' => '查看更多市场',
        'why_choose_us' => '为什么选择我们？',
        'secure_storage' => '安全存储',
        'secure_storage_desc' => '我们将绝大部分数字资产存储在安全的离线存储中。',
        'protected_insurance' => '保险保护',
        'protected_insurance_desc' => '存储在我们服务器上的加密货币受我们的保险政策保护。',
        'industry_best_practices' => '行业最佳实践',
        'industry_best_practices_desc' => 'NovaEx 支持多种最流行的数字货币。',
        'platform_desc' => '我们的平台为零售和机构交易者提供具有先进功能和稳健基础设施的无缝交易体验。',
        'partners' => '合作伙伴',
        'partners_subtitle' => '深受全球领先组织和金融机构的信任。',
        'footer_desc' => 'NovaEx 是全球领先的数字资产交易平台，为全球用户提供安全稳定的交易服务。',
        'about' => '关于',
        'about_us' => '关于我们',
        'careers' => '职业介绍',
        'news' => '新闻',
        'legal_privacy' => '法律与隐私',
        'terms_service' => '服务条款',
        'products' => '产品',
        'spot_trading' => '现货交易',
        'futures_trading' => '合约交易',
        'flash_swap' => '闪兑',
        'staking' => '质押',
        'asset_management' => '资产管理',
        'support' => '支持',
        'help_center' => '帮助中心',
        'submit_request' => '提交请求',
        'api_docs' => 'API 文档',
        'fee_schedule' => '费率标准',
        'service_status' => '服务状态',
        'all_rights_reserved' => '保留所有权利。',
        'cookie_policy' => 'Cookie 政策',
        'security' => '安全',
        'system_status_normal' => '系统状态：正常',
        'personal_center' => '个人中心',
        'uid' => 'UID',
        'credit_score' => '信用分',
        'kyc_status' => '身份认证',
        'kyc_none' => '未认证',
        'kyc_pending' => '审核中',
        'kyc_approved' => '已认证',
        'kyc_rejected' => '认证失败',
        'kyc_submit' => '提交认证',
        'total_balance' => '总资产',
        'available_balance' => '可用余额',
        'order_book' => '订单簿',
        'trade_panel' => '下单面板',
        'k_line' => 'K线图',
        'open_orders' => '当前委托',
        'order_history' => '历史委托',
        'trade_history' => '成交记录',
        'funds_flow' => '资金流水',
        'current_positions' => '当前持仓',
        'limit' => '限价',
        'market' => '市价',
        'price' => '价格',
        'amount' => '数量',
        'total' => '总额',
        'buy' => '买入',
        'sell' => '卖出',
        'leverage' => '杠杆',
        'tp_sl' => '止盈止损',
        'take_profit' => '止盈',
        'stop_loss' => '止损',
        'cost' => '成本',
        'open_long' => '做多',
        'open_short' => '做空',
        'security_settings' => '安全设置',
        'asset_details' => '资产详情',
        'transaction_records' => '交易记录',
        'level' => '等级',
        'crypto_markets' => '加密货币行情',
        '24h_volume' => '24小时成交量',
        'fear_greed' => '贪婪恐惧指数',
        'btc_dominance' => '比特币占有率',
        'favorites' => '自选',
        'all_crypto' => '所有币种',
        'asset' => '资产',
        '24h_high_low' => '24小时最高/最低',
        'deposit_assets' => '充值资产',
        'deposit_method_tip' => '请选择您偏好的充值方式。',
        'fiat_deposit' => '法币充值',
        'crypto_deposit' => '加密货币充值',
        'bank_transfer' => '本地银行转账',
        'blockchain_transfer' => '区块链转账',
        'support_20_global' => '支持20多种全球货币',
        'safe_compliant' => '安全合规的通道',
        'fast_processing' => '24/7 快速处理',
        'no_service_fee' => '无服务费',
        'select_currency' => '选择币种',
        'deposit_amount' => '充值金额',
        'matching_instructions' => '匹配说明',
        'matching_tip' => '我们的智能匹配系统将为您匹配认证商户。确认后，您将收到银行账户详情。请在时限内完成转账。',
        'match_now' => '立即匹配商户',
        'select_network' => '选择网络',
        'get_address' => '获取充值地址',
        'withdraw_assets' => '提现资产',
        'withdraw_tip' => '安全地将 USDT 提现到您的外部钱包。',
        'withdraw_address' => '提现地址',
        'trading_password' => '交易密码',
        'submit_withdrawal' => '提交提现',
        'withdrawal_tips' => '提现提示',
        'withdrawal_tip_1' => '请仔细检查目标地址。我们无法找回发送到错误地址的资金。',
        'withdrawal_tip_2' => 'TRC20 提现通常在 5-10 分钟内到账。',
        'withdrawal_tip_3' => '高峰时段，提现将进行人工安全审计。',
        'withdrawal_tip_4' => '手续费：每笔交易 1 USDT。',
        'recent_history' => '最近记录',
        'no_records' => '暂无记录',
        'max' => '最大',
        'customer_service' => '在线客服',
        'chat_welcome' => '您好！请问有什么可以帮您？',
        'type_message' => '输入消息...', 
        'matching_account' => '正在匹配收款账户...', 
        'matching_desc' => '系统正在为您匹配安全的本地收款账户。请稍候。',
        'crypto' => '加密货币',
        'search_market' => '搜索币种',
        'more_pairs' => '更多币种',
        'limit_order' => '限价',
        'market_order' => '市价',
        'available' => '可用',
        'buy_long' => '买入开多',
        'sell_short' => '卖出开空',
        'open_position' => '开仓',
        'close_position' => '平仓',
        'cross' => '全仓',
        'isolated' => '逐仓',
        'positions' => '当前持仓',
        'no_positions' => '暂无持仓',
        'perpetual' => '永续合约',
        'delivery' => '交割合约',
        'fee' => '手续费',
        'max_open' => '最大可开',
        'time' => '时间',
        'pair' => '币对',
        'side' => '方向',
        'filled' => '已成交',
        'status' => '状态',
        'load_more' => '加载更多',
    ]
];

$lang = $_SESSION['lang'] ?? 'en';
if (isset($_GET['lang']) && array_key_exists($_GET['lang'], $translations)) {
    $_SESSION['lang'] = $_GET['lang'];
    $lang = $_GET['lang'];
}

function __($key, $default = '') {
    global $translations, $lang;
    return $translations[$lang][$key] ?? ($default ?: $key);
}