-
app/View/Components/LanguageSelector.php
Open in GitHubuse Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Route; use Illuminate\Support\Str; use Illuminate\View\Component; class LanguageSelector extends Component { public $current_language; public $formatted_languages; public function __construct() { $this->formatted_languages = collect(Config::get('localized-routes.supported-locales', []))->map(function ($lang) { return [ 'language_name' => $lang, 'language_name_native' => Config::get("localized-routes.locales-name-native.{$lang}", Str::upper($lang)), 'language_url' => Route::localizedUrl($lang), ]; }); $this->current_language = $this->formatted_languages->first(function ($languageObject) { return $languageObject['language_name'] === App::getLocale(); })['language_name_native']; } public function render() { return view('components.language-selector'); } }
-
resources/views/partials/modules/header.blade.php
Open in GitHub@if (Config::has('localized-routes.supported-locales')) <x-language-selector /> @endif