<?php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

$translations = [
    'en' => [
        'nav_home' => 'Home',
        'nav_market' => 'Markets',
        'nav_trade' => 'Trade',
        'nav_spot' => 'Spot',
        'nav_futures' => 'Futures',
        'nav_options' => 'Second Contract',
        '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',
        'nav_security' => 'Security',
        'nav_app_download' => 'APP Download',
        'nav_help' => 'Help',
        
        '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',
        'join_now' => 'Join Now',
        'start_trading' => 'Start Trading',
        'earn_now' => 'Earn Now',
        
        'market_trends' => 'Market Trends',
        'view_more_markets' => 'View More',
        'pair' => 'Pair',
        'last_price' => 'Last Price',
        '24h_change' => '24h Change',
        'market_cap' => 'Market Cap',
        
        'why_choose_us' => 'Why Choose NovaEx?',
        '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' => '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.',
        
        'global_partners' => 'Global 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',
        
        'search_pair' => 'Search Pairs',
        'search_contract' => 'Search Contracts',
        'price' => 'Price',
        'amount' => 'Amount',
        'total' => 'Total',
        'available' => 'Available',
        'limit' => 'Limit',
        'market' => 'Market',
        'buy' => 'Buy',
        'sell' => 'Sell',
        'buy_long' => 'Buy Long',
        'sell_short' => 'Sell Short',
        'open_long' => 'Open Long',
        'open_short' => 'Open Short',
        'leverage' => 'Leverage',
        'margin' => 'Margin',
        'isolated' => 'Isolated',
        'cross' => 'Cross',
        'order_book' => 'Order Book',
        'open_orders' => 'Open Orders',
        'current_orders' => 'Current Orders',
        'order_history' => 'Order History',
        'history_orders' => 'History Orders',
        'positions' => 'Positions',
        'current_positions' => 'Current Positions',
        'no_records' => 'No Records',
        'cancel' => 'Cancel',
        'confirm' => 'Confirm',
        'adjust_leverage' => 'Adjust Leverage',
        'close_position' => 'Close',
        'time' => 'Time',
        'status' => 'Status',
        'action' => 'Action',
        'type' => 'Type',
        'direction' => 'Side',
        'filled' => 'Filled',
        
        'settlement_time' => 'Settlement Time',
        'buy_amount' => 'Order Amount',
        'min_order' => 'Min Order',
        'buy_up' => 'Buy Up',
        'buy_down' => 'Buy Down',
        'profit' => 'Profit',
        'expected_profit' => 'Expected Profit',
        'in_progress' => 'In Progress',
        'settled' => 'Settled',
        'opening_price' => 'Opening Price',
        'closing_price' => 'Closing Price',
        'countdown' => 'Countdown',
        'pnl' => 'P/L',
        'trading_executing' => 'Trading Executing',
        'waiting_settlement' => 'Waiting for Settlement',
        'system_matching_engine' => 'System matching engine',
        
        'kyc_status' => 'KYC Verification',
        'kyc_none' => 'Unverified',
        'kyc_pending' => 'Pending',
        'kyc_approved' => 'Verified',
        'kyc_rejected' => 'Rejected',
        'security_settings' => 'Security Settings',
        'total_balance' => 'Total Balance',
        'asset_details' => 'Asset Details',
        'transaction_records' => 'Records',
        'credit_score' => 'Credit Score',
        'level' => 'Level',
        'withdraw_amount' => 'Withdraw Amount',
        'withdraw_address' => 'Withdraw Address',
        'fund_password' => 'Fund Password',
        'withdraw_all' => 'Withdraw All',
        'min_withdraw' => 'Min Withdraw',
        'withdraw_fee' => 'Fee',
        'withdraw_submit' => 'Confirm Withdrawal',
        'withdraw_tip' => 'Please jump to customer service to confirm withdrawal after submission.',
        'payout_format_received' => 'Payout Format Received',
    ],
    'zh' => [
        'nav_home' => '首页',
        'nav_market' => '行情',
        'nav_trade' => '交易',
        'nav_spot' => '现货交易',
        'nav_futures' => '合约交易',
        'nav_options' => '秒合约',
        'nav_mining' => '挖矿',
        'nav_convert' => '闪兑',
        'nav_assets' => '资产',
        'nav_total_assets' => '总资产',
        'nav_deposit' => '充值',
        'nav_withdraw' => '提现',
        'nav_login' => '登录',
        'nav_register' => '注册',
        'nav_profile' => '个人中心',
        'nav_logout' => '退出登录',
        'nav_security' => '安全中心',
        'nav_app_download' => 'APP 下载',
        'nav_help' => '帮助中心',
        
        'hero_title' => '在 NovaEx 购买、交易和持有 350 多种加密货币',
        'hero_subtitle' => '加入全球最大的加密货币交易所，享受最低的费用和最好的安全性。',
        'btn_start' => '立即开始',
        'btn_download' => '下载应用',
        'app_download' => 'APP 下载',
        'download_qr_tip' => '下载应用并获得高达 50 USDT 的奖励',
        'join_now' => '立即加入',
        'start_trading' => '开始交易',
        'earn_now' => '立即赚取',
        
        'market_trends' => '市场趋势',
        'view_more_markets' => '查看更多',
        'pair' => '币对',
        'last_price' => '最新价',
        '24h_change' => '24h 涨跌',
        'market_cap' => '市值',
        
        'why_choose_us' => '为什么选择 NovaEx?',
        'secure_storage' => '安全存储',
        'secure_storage_desc' => '我们将绝大部分数字资产存储在安全的离线存储中。',
        'protected_insurance' => '保险保护',
        'protected_insurance_desc' => '存储在我们服务器上的加密货币受我们的保险政策保护。',
        'industry_best_practices' => '行业最佳实践',
        'industry_best_practices_desc' => 'NovaEx 支持多种最流行的数字货币。',
        'platform_desc' => '我们的平台为零售和机构交易者提供具有先进功能和稳健基础设施的无缝交易体验。',
        
        'global_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' => '系统状态：正常',
        
        'search_pair' => '搜索币对',
        'search_contract' => '搜索合约',
        'price' => '价格',
        'amount' => '数量',
        'total' => '总额',
        'available' => '可用',
        'limit' => '限价',
        'market' => '市价',
        'buy' => '买入',
        'sell' => '卖出',
        'buy_long' => '看多/买入',
        'sell_short' => '看空/卖出',
        'open_long' => '买入开多',
        'open_short' => '卖出开空',
        'leverage' => '杠杆',
        'margin' => '保证金',
        'isolated' => '逐仓',
        'cross' => '全仓',
        'order_book' => '订单簿',
        'open_orders' => '当前委托',
        'current_orders' => '当前委托',
        'order_history' => '历史委托',
        'history_orders' => '历史委托',
        'positions' => '当前持仓',
        'current_positions' => '当前持仓',
        'no_records' => '暂无记录',
        'cancel' => '取消',
        'confirm' => '确认',
        'adjust_leverage' => '调整杠杆',
        'close_position' => '平仓',
        'time' => '时间',
        'status' => '状态',
        'action' => '操作',
        'type' => '类型',
        'direction' => '方向',
        'filled' => '已成交',
        
        'settlement_time' => '结算时间',
        'buy_amount' => '买入金额',
        'min_order' => '最小下单',
        'buy_up' => '买涨',
        'buy_down' => '买跌',
        'profit' => '收益',
        'expected_profit' => '预期收益',
        'in_progress' => '进行中',
        'settled' => '已结算',
        'opening_price' => '买入价',
        'closing_price' => '结算价',
        'countdown' => '倒计时',
        'pnl' => '盈亏',
        'trading_executing' => '交易执行中',
        'waiting_settlement' => '等待结算',
        'system_matching_engine' => '系统撮合引擎',
        
        'kyc_status' => '实名认证',
        'kyc_none' => '未认证',
        'kyc_pending' => '审核中',
        'kyc_approved' => '已认证',
        'kyc_rejected' => '未通过',
        'security_settings' => '安全中心',
        'total_balance' => '总资产',
        'asset_details' => '资产详情',
        'transaction_records' => '交易记录',
        'credit_score' => '信用分',
        'level' => '等级',
        'withdraw_amount' => '提现金额',
        'withdraw_address' => '提现地址',
        'fund_password' => '资金密码',
        'withdraw_all' => '全部提现',
        'min_withdraw' => '最小提现',
        'withdraw_fee' => '手续费',
        'withdraw_submit' => '确认订单',
        'withdraw_tip' => '提交后请跳转客服对话窗确认。',
        'payout_format_received' => '收到出款格式',
    ]
];

if (!isset($_SESSION['lang'])) {
    $_SESSION['lang'] = 'en';
}

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

$lang = $_SESSION['lang'];

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