<?php


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

$lang = $_SESSION['lang'] ?? 'en';

$langFile = __DIR__ . "/lang/{$lang}.php";

if (!file_exists($langFile)) {
    $lang = 'en';
    $langFile = __DIR__ . "/lang/en.php";
}

$GLOBALS['current_lang'] = $lang;
$GLOBALS['translations'] = require $langFile;

function __t($key) {
    return $GLOBALS['translations'][$key] ?? $key;
}
