locale fix

This commit is contained in:
2025-11-13 11:49:41 +05:00
parent c2e9198dbc
commit 294ec0144d
7 changed files with 304 additions and 133 deletions

View File

@@ -8,6 +8,9 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\ServiceProvider;
use Spatie\Translatable\HasTranslations;
use BezhanSalleh\LanguageSwitch\LanguageSwitch;
use BezhanSalleh\LanguageSwitch\Events\LocaleChanged;
use Illuminate\Support\Facades\Event;
class AppServiceProvider extends ServiceProvider
{
@@ -33,6 +36,17 @@ class AppServiceProvider extends ServiceProvider
->locales(array_keys(baseLocales()));
});
LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
$switch
->locales(['tk', 'en', 'ru']);
});
Event::listen(function (LocaleChanged $event) {
if (array_key_exists($event->locale, baseLocales())) {
user()->update(['locale' => $event->locale]);
}
});
/**
* Order by translation for spatie/laravel-translatable
*