getExtension())) { 'po' => new PoLoader(), 'mo' => new MoLoader(), default => throw new Exception("There's no suitable gettext loader for this file type") }; } /** * Loads the translations from a file */ public static function loadTranslations(string $path): Translations { return self::getLoader($path)->loadFile($path); } /** * Loads the translations from a file as an array and caches the content physically as a PHP file in order to use the opcache */ public static function loadArray(string $path, bool $useCache = false): array { $loader = fn () => (new ArrayGenerator(['includeEmpty' => false]))->generateArray(static::loadTranslations($path)); $key = __METHOD__ . static::MAX_CACHE_LIFETIME . $path . filemtime($path); return $useCache ? Cache::remember($key, DateInterval::createFromDateString(static::MAX_CACHE_LIFETIME), $loader) : $loader(); } }