<?php
/**
 * Translation Helper - Server-side translation system
 * No external APIs, no CSP issues, reliable and simple
 */

// Get current language from session
$current_language = $_SESSION['selected_language'] ?? 'ENG';

// Translation dictionary
$translations = [
    'ITA' => [
        'NEED_HELP' => 'AIUTO',
        'FREE_RETURNS' => 'RESI GRATUITI E SPEDIZIONE STANDARD SU ORDINI $99+',
        'FREE_RETURNS_FULL' => 'RESI GRATUITI E SPEDIZIONE STANDARD SU ORDINI $99+',
        'home' => 'HOME',
        'shop' => 'NEGOZIO',
        'categories' => 'CATEGORIE',
        'about' => 'CHI SIAMO',
        'blog' => 'BLOG',
        'contact' => 'CONTATTI',
        'cart' => 'CARRELLO',
        'featured_categories' => 'CATEGORIE DESTACATE',
        'new_arrivals' => 'NUOVI ARRIVI',
        'best_sellers' => 'BEST SELLER',
        'on_sale' => 'IN SCONTO',
        'women_fashion' => 'MODA DONNA',
        'let_get_look' => 'Vedi la collezione',
        'shop_now' => 'ACQUISTA ORA',
        'welcome' => 'Benvenuti in Emporio Sport',
        'description' => 'Il tuo negozio di moda online preferito',
        'price' => 'Prezzo',
        'sale' => 'Sconto',
        'products' => 'Prodotti',
        'search' => 'Cerca',
        'login' => 'Accedi',
        'logout' => 'Esci',
        'account' => 'Account',
        'settings' => 'Impostazioni',
        'language' => 'Lingua',
        'currency' => 'Valuta',
    ],
    'ENG' => [
        'NEED_HELP' => 'NEED HELP',
        'FREE_RETURNS' => 'FREE RETURNS & STANDARD SHIPPING ON ORDERS $99+',
        'FREE_RETURNS_FULL' => 'FREE RETURNS & STANDARD SHIPPING ON ORDERS $99+',
        'home' => 'HOME',
        'shop' => 'SHOP',
        'categories' => 'CATEGORIES',
        'about' => 'ABOUT',
        'blog' => 'BLOG',
        'contact' => 'CONTACT',
        'cart' => 'CART',
        'featured_categories' => 'FEATURED CATEGORIES',
        'new_arrivals' => 'NEW ARRIVALS',
        'best_sellers' => 'BEST SELLERS',
        'on_sale' => 'ON SALE',
        'women_fashion' => 'WOMEN FASHION',
        'let_get_look' => 'Let get a look',
        'shop_now' => 'SHOP NOW',
        'welcome' => 'Welcome to Emporio Sport',
        'description' => 'Your favorite online fashion store',
        'price' => 'Price',
        'sale' => 'Sale',
        'products' => 'Products',
        'search' => 'Search',
        'login' => 'Login',
        'logout' => 'Logout',
        'account' => 'Account',
        'settings' => 'Settings',
        'language' => 'Language',
        'currency' => 'Currency',
    ],
    'ESP' => [
        'NEED_HELP' => 'NECESITA AYUDA',
        'FREE_RETURNS' => 'DEVOLUCIONES GRATUITAS Y ENVÍO ESTÁNDAR EN PEDIDOS $99+',
        'FREE_RETURNS_FULL' => 'DEVOLUCIONES GRATUITAS Y ENVÍO ESTÁNDAR EN PEDIDOS $99+',
        'home' => 'INICIO',
        'shop' => 'TIENDA',
        'categories' => 'CATEGORÍAS',
        'about' => 'ACERCA DE',
        'blog' => 'BLOG',
        'contact' => 'CONTACTO',
        'cart' => 'CARRITO',
        'featured_categories' => 'CATEGORÍAS DESTACADAS',
        'new_arrivals' => 'NUEVAS LLEGADAS',
        'best_sellers' => 'MÁS VENDIDOS',
        'on_sale' => 'EN VENTA',
        'women_fashion' => 'MODA PARA MUJERES',
        'let_get_look' => 'Ver la colección',
        'shop_now' => 'COMPRAR AHORA',
        'welcome' => 'Bienvenido a Emporio Sport',
        'description' => 'Tu tienda de moda en línea favorita',
        'price' => 'Precio',
        'sale' => 'Venta',
        'products' => 'Productos',
        'search' => 'Buscar',
        'login' => 'Iniciar sesión',
        'logout' => 'Cerrar sesión',
        'account' => 'Cuenta',
        'settings' => 'Configuración',
        'language' => 'Idioma',
        'currency' => 'Moneda',
    ],
    'GER' => [
        'NEED_HELP' => 'BENÖTIGEN SIE HILFE',
        'FREE_RETURNS' => 'KOSTENLOSE RÜCKGABEN UND STANDARDVERSAND FÜR BESTELLUNGEN ÜBER $99+',
        'FREE_RETURNS_FULL' => 'KOSTENLOSE RÜCKGABEN UND STANDARDVERSAND FÜR BESTELLUNGEN ÜBER $99+',
        'home' => 'STARTSEITE',
        'shop' => 'SHOP',
        'categories' => 'KATEGORIEN',
        'about' => 'ÜBER UNS',
        'blog' => 'BLOG',
        'contact' => 'KONTAKT',
        'cart' => 'WARENKORB',
        'featured_categories' => 'EMPFOHLENE KATEGORIEN',
        'new_arrivals' => 'NEUANKÖMMLINGE',
        'best_sellers' => 'BESTSELLER',
        'on_sale' => 'IM ANGEBOT',
        'women_fashion' => 'FRAUENMODE',
        'let_get_look' => 'Schauen Sie sich die Kollektion an',
        'shop_now' => 'JETZT KAUFEN',
        'welcome' => 'Willkommen bei Emporio Sport',
        'description' => 'Ihr liebster Online-Modeboutique',
        'price' => 'Preis',
        'sale' => 'Verkauf',
        'products' => 'Produkte',
        'search' => 'Suche',
        'login' => 'Anmelden',
        'logout' => 'Abmelden',
        'account' => 'Konto',
        'settings' => 'Einstellungen',
        'language' => 'Sprache',
        'currency' => 'Währung',
    ],
];

/**
 * Get translated text
 * @param string $key Translation key
 * @param string $fallback Fallback text if key not found
 * @return string Translated text
 */
function __($key, $fallback = '') {
    global $translations, $current_language;
    
    $lang = $current_language ?? 'ENG';
    
    if (isset($translations[$lang][$key])) {
        return $translations[$lang][$key];
    }
    
    // Fallback to English
    if (isset($translations['ENG'][$key])) {
        return $translations['ENG'][$key];
    }
    
    // Return fallback or key itself
    return $fallback ?: $key;
}
?>
