*/ public static function languages() { return static::localesFromManifest() ?? static::localesFromScan(); } /** * Full locale metadata (code, name, nativeName) from the manifest, * sorted by display name. Empty array if the manifest is missing. * * @return array */ public static function locales(): array { $path = lang_path('locales.json'); if (! is_file($path)) { return []; } $data = json_decode((string) file_get_contents($path), true); return is_array($data) ? $data : []; } /** * @return array|null */ protected static function localesFromManifest(): ?array { $locales = static::locales(); if (empty($locales)) { return null; } return array_values(array_filter(array_map( fn ($l) => $l['code'] ?? null, $locales ))); } /** * @return array */ protected static function localesFromScan(): array { $dir = lang_path(); return Arr::flatten(array_diff(scandir($dir), ['..', '.', 'vendor', '.DS_Store', 'locales.json'])); } }