yanzi wrote a reply+100 XP
4mos ago
For newer Laravel versions (where the lang folder is not in the resources anymore but in the project's base folder) and with some more functionality:
/**
* @param array array of required name replacements, eg. when you want to replace the 'en_BR' with just 'en', put ['en_BR' => 'en']
* @return array return an array of available locales, eg. ['en', 'fr']
*/
private function getAllLocales(array $replacements = []): array {
$locales = collect(array_diff(
scandir(base_path('lang')),
['..', '.'] // remove these strings from the result
))->filter(fn($item) => !str_contains($item, ".")) // removes all the files (these typically contain a dot in their name)
->map(fn($item) => $replacements[$item] ?? $item)->toArray(); // replaces all the given names (as key) in the $replacements argument with the specified new name (as value)
return array_values($locales);
}
yanzi wrote a comment+100 XP
5mos ago
@neilstee same here... how many hours I have lost trying to make it work with the <Head>. F***ing Inertia :)
I have found in the inertia docs (https://inertiajs.com/title-and-meta) something that is should get rid of the inertia attribute, but it just does not work... Have you ever made it work without teleport?