<?php
function currentLang(): string {
    if (isset($_GET['lang']) && in_array($_GET['lang'], ['en', 'sr'], true)) {
        $_SESSION['lang'] = $_GET['lang'];
    }
    if (!isset($_SESSION['lang'])) {
        $_SESSION['lang'] = 'en';
    }
    return $_SESSION['lang'];
}

function t(string $key): string {
    static $translations = null;

    $lang = currentLang();
    if ($translations === null) {
        $file = __DIR__ . '/../lang/' . $lang . '.php';
        $translations = file_exists($file) ? include $file : [];
    }

    return $translations[$key] ?? $key;
}
