<?php
declare(strict_types=1);

/**
 * 多语言类
 * 语言包是纯 PHP 数组文件（key => 译文），找不到 key 时原样返回 key 本身兜底
 */
final class Lang
{
    /** @var array<string, string> 当前已加载的语言字典 */
    private static array $dict = [];

    /**
     * 加载语言包
     * @param string $locale 语言标识，对应 [langDir]/[locale].php
     * @param string $langDir 语言包所在目录
     */
    public static function load(string $locale, string $langDir): void
    {
        $file = rtrim($langDir, '/') . '/' . $locale . '.php';
        self::$dict = is_file($file) ? require $file : [];
    }

    /**
     * 取译文，找不到时原样返回 $key
     */
    public static function get(string $key): string
    {
        return self::$dict[$key] ?? $key;
    }
}
