Files
ppeasy_vg12/app/Support/Translations.php
T
2026-10-09 08:21:06 +02:00

48 lines
1.2 KiB
PHP

<?php
namespace App\Support;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Lang;
class Translations
{
/**
* In-request memoisation, keyed by locale.
*
* @var array<string, array<string, string>>
*/
private static array $catalogs = [];
/**
* The JSON translation catalog for the given locale.
*
* Vanguard uses English strings as translation keys ( __('Total Users') ),
* which live in the JSON language files. Those are exactly the strings the
* Vue layer needs, and plugin JSON translations are merged in automatically
* because plugins register them via loadJsonTranslationsFrom().
*
* @return array<string, string>
*/
public static function catalog(?string $locale = null): array
{
$locale ??= App::getLocale();
if (isset(self::$catalogs[$locale])) {
return self::$catalogs[$locale];
}
$translations = Lang::getLoader()->load($locale, '*', '*');
return self::$catalogs[$locale] = is_array($translations) ? $translations : [];
}
/**
* Reset the memoised catalogs. Intended for use in tests.
*/
public static function flush(): void
{
self::$catalogs = [];
}
}