PHP code example of amrikasir / lang-selector
1. Go to this page and download the library: Download amrikasir/lang-selector library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
amrikasir / lang-selector example snippets
protected $middlewareGroups = [
'web' => [
// ...
\Kaldiaris\LangSelector\Http\Middleware\LocaleMiddleware::class,
],
];
return [
'available_locales' => [
'en' => 'English',
'id' => 'Bahasa Indonesia',
// add more as needed
],
'default_locale' => 'en',
];
bash
php artisan vendor:publish --tag=lang-selector-config
php artisan vendor:publish --tag=lang-selector-views
resources/views/vendor/lang-selector/livewire/language-selector.blade.php
html
<div class="relative">
<button wire:click="$toggle('open')" class="px-3 py-2 rounded bg-gray-100 hover:bg-gray-200">
{{ $locales[$current] ?? strtoupper($current) }}
</button>
@if ($open ?? false)
<div class="absolute bg-white border rounded mt-1 shadow">
@foreach ($locales as $key => $label)
<button wire:click="setLocale('{{ $key }}')" class="block w-full text-left px-4 py-2 hover:bg-gray-100">
{{ $label }}
</button>
@endforeach
</div>
@endif
</div>