🌐 Introduce dynamic domain-based locale and country handling

- Added `DomainMiddleware` to dynamically set locale, language-country session, and app name based on domain.
- Updated views and components to leverage `lang_country` session for language and region-specific content.
- Enhanced country parameter retrieval with `config('app.domain_country')` as fallback.
- Refined language filtering by scanning available language files dynamically.
- Added language-specific assets and translations (`nl.json`, `es.json`) with improved language-region associations.
- Updated `app-logo-icon` to display region-specific images or default SVGs.
- Improved views with cleaner, dynamic rendering and session-aware functionalities.
This commit is contained in:
HolgerHatGarKeineNode
2025-11-23 20:45:29 +01:00
parent c48455a6be
commit 6f7ee806ae
32 changed files with 962 additions and 42 deletions

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@@ -10,11 +10,25 @@
<flux:accordion.content>
@php
$languages = [
// Scan lang folder for available languages
$availableLanguages = collect(glob(base_path('lang/*.json')))
->map(fn($file) => pathinfo($file, PATHINFO_FILENAME))
->toArray();
$allLanguages = [
'de' => ['name' => 'Deutsch', 'countries' => ['de-DE', 'de-AT', 'de-CH']],
'en' => ['name' => 'English', 'countries' => ['en-GB', 'en-US', 'en-AU', 'en-CA']],
'es' => ['name' => 'Español', 'countries' => ['es-ES', 'es-CL', 'es-CO']],
'nl' => ['name' => 'Nederlands', 'countries' => ['nl-NL', 'nl-BE']],
'pt' => ['name' => 'Português', 'countries' => ['pt-PT']],
];
// Filter languages based on available JSON files and allowed languages
$languages = array_filter($allLanguages, function($data, $key) use ($availableLanguages) {
return in_array($key, $availableLanguages) &&
count(array_intersect($data['countries'], config('lang-country.allowed'))) > 0;
}, ARRAY_FILTER_USE_BOTH);
$currentLangCountry = session('lang_country', config('lang-country.fallback'));
@endphp

View File

@@ -32,7 +32,7 @@ class extends Component {
session(['auth.password_confirmed_at' => time()]);
$this->redirectIntended(default: route('dashboard', ['country' => str(session('lang_country', 'de'))->after('-')->lower()], absolute: false), navigate: true);
$this->redirectIntended(default: route('dashboard', ['country' => str(session('lang_country', config('app.domain_country')))->after('-')->lower()], absolute: false), navigate: true);
}
}; ?>

View File

@@ -36,9 +36,12 @@ class extends Component {
public ?string $url = null;
public ?string $lnurl = null;
public ?string $qrCode = null;
public string $currentLangCountry = 'de-DE';
public function mount(): void
{
$this->currentLangCountry = session('lang_country');
// Nur beim ersten Mount initialisieren
if ($this->k1 === null) {
$this->k1 = bin2hex(str()->random(32));
@@ -64,7 +67,7 @@ class extends Component {
Auth::loginUsingId($user->id);
Session::regenerate();
$this->redirectIntended(
default: route('dashboard', ['country' => str(session('lang_country', 'de'))->after('-')->lower()], absolute: false),
default: route('dashboard', ['country' => str(session('lang_country', config('app.domain_country')))->after('-')->lower()], absolute: false),
navigate: true,
);
return;
@@ -85,9 +88,12 @@ class extends Component {
RateLimiter::clear($this->throttleKey());
Session::regenerate();
session([
'lang_country' => $this->currentLangCountry,
]);
$this->redirectIntended(
default: route('dashboard', ['country' => str(session('lang_country', 'de'))->after('-')->lower()], absolute: false),
default: route('dashboard', ['country' => str(session('lang_country', config('app.domain_country')))->after('-')->lower()], absolute: false),
navigate: true
);
}
@@ -134,8 +140,12 @@ class extends Component {
\App\Models\User::find(1)
->notify(new ModelCreatedNotification($user, 'users'));
auth()->login($user);
Session::regenerate();
session([
'lang_country' => $this->currentLangCountry,
]);
return to_route('dashboard', ['country' => str(session('lang_country', 'de'))->after('-')->lower()]);
return to_route('dashboard', ['country' => str(session('lang_country', config('app.domain_country')))->after('-')->lower()]);
}
return true;

View File

@@ -35,7 +35,7 @@ class extends Component {
Auth::login($user);
$this->redirectIntended(route('dashboard', ['country' => str(session('lang_country', 'de'))->after('-')->lower()],absolute: false), navigate: true);
$this->redirectIntended(route('dashboard', ['country' => str(session('lang_country', config('app.domain_country')))->after('-')->lower()],absolute: false), navigate: true);
}
}; ?>

View File

@@ -17,7 +17,7 @@ class extends Component {
public function sendVerification(): void
{
if (Auth::user()->hasVerifiedEmail()) {
$this->redirectIntended(default: route('dashboard', ['country' => str(session('lang_country', 'de'))->after('-')->lower()],absolute: false), navigate: true);
$this->redirectIntended(default: route('dashboard', ['country' => str(session('lang_country', config('app.domain_country')))->after('-')->lower()],absolute: false), navigate: true);
return;
}

View File

@@ -17,7 +17,7 @@ class extends Component {
public function mount(): void
{
$this->country = request()->route('country');
$this->country = request()->route('country', config('app.domain_country'));
}
public function with(): array

View File

@@ -9,7 +9,7 @@ new class extends Component {
public function mount(): void
{
$this->currentCountry = request()->route('country', 'de');
$this->currentCountry = request()->route('country', config('app.domain_country'));
$this->currentRouteName = request()->route()->getName();
$this->currentRouteParams = request()->route()->parameters();
}

View File

@@ -37,7 +37,7 @@ class extends Component {
public function mount(): void
{
$this->country = request()->route('country');
$this->country = request()->route('country', config('app.domain_country'));
$timezone = auth()->user()->timezone ?? 'Europe/Berlin';
if ($this->event) {

View File

@@ -17,7 +17,7 @@ class extends Component {
public function mount(): void
{
$this->country = request()->route('country');
$this->country = request()->route('country', config('app.domain_country'));
}
public function with(): array

View File

@@ -17,7 +17,7 @@ class extends Component {
public function mount(): void
{
$this->country = request()->route('country');
$this->country = request()->route('country', config('app.domain_country'));
}
public function with(): array

View File

@@ -18,7 +18,7 @@ class extends Component {
public function mount(): void
{
$this->country = request()->route('country');
$this->country = request()->route('country', config('app.domain_country'));
}
public function addMeetup()

View File

@@ -17,7 +17,7 @@ class extends Component {
public function mount(): void
{
$this->country = request()->route('country');
$this->country = request()->route('country', config('app.domain_country'));
}
public function with(): array

View File

@@ -31,7 +31,7 @@ class extends Component {
public function mount(): void
{
$this->country = request()->route('country');
$this->country = request()->route('country', config('app.domain_country'));
$timezone = auth()->user()->timezone ?? 'Europe/Berlin';
if ($this->event) {

View File

@@ -17,7 +17,7 @@ class extends Component {
public function mount(): void
{
$this->country = request()->route('country');
$this->country = request()->route('country', config('app.domain_country'));
}
public function with(): array

View File

@@ -25,7 +25,7 @@ class extends Component {
public function mount(): void
{
$this->country = request()->route('country');
$this->country = request()->route('country', config('app.domain_country'));
$this->name = auth()->user()->name ?? '';
$this->loadAttendees();
}

View File

@@ -17,7 +17,7 @@ class extends Component {
public function mount(): void
{
$this->country = request()->route('country');
$this->country = request()->route('country', config('app.domain_country'));
}
public function with(): array

View File

@@ -16,7 +16,7 @@ class extends Component {
public function mount(): void
{
$this->country = request()->route('country');
$this->country = request()->route('country', config('app.domain_country'));
$geoCountry = \Lwwcas\LaravelCountries\Models\Country::query()
->where('iso_alpha_2', str($this->country)->upper())
->first()

View File

@@ -64,7 +64,7 @@ class extends Component {
$user = Auth::user();
if ($user->hasVerifiedEmail()) {
$this->redirectIntended(default: route('dashboard', ['country' => str(session('lang_country', 'de'))->after('-')->lower()],absolute: false));
$this->redirectIntended(default: route('dashboard', ['country' => str(session('lang_country', config('app.domain_country')))->after('-')->lower()],absolute: false));
return;
}
@@ -127,11 +127,22 @@ class extends Component {
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
@php
$languages = [
// Scan lang folder for available languages
$availableLanguages = collect(glob(base_path('lang/*.json')))
->map(fn($file) => pathinfo($file, PATHINFO_FILENAME))
->toArray();
$allLanguages = [
'de' => ['name' => 'Deutsch', 'countries' => ['de-DE', 'de-AT', 'de-CH']],
'en' => ['name' => 'English', 'countries' => ['en-GB', 'en-US', 'en-AU', 'en-CA']],
'es' => ['name' => 'Español', 'countries' => ['es-ES', 'es-CL', 'es-CO']],
'nl' => ['name' => 'Nederlands', 'countries' => ['nl-NL', 'nl-BE']],
'pt' => ['name' => 'Português', 'countries' => ['pt-PT', 'pt-BR']],
];
// Filter languages based on available JSON files
$languages = array_filter($allLanguages, fn($key) => in_array($key, $availableLanguages), ARRAY_FILTER_USE_KEY);
$currentLangCountry = session('lang_country', config('lang-country.fallback'));
@endphp

View File

@@ -17,7 +17,7 @@ class extends Component {
public function mount(): void
{
$this->country = request()->route('country');
$this->country = request()->route('country', config('app.domain_country'));
}
public function with(): array

View File

@@ -13,12 +13,12 @@ class extends Component {
public function goToMeetups(): void
{
$this->redirect(route('meetups.index', ['country' => str(session('lang_country', 'de'))->after('-')->lower()]), navigate: true);
$this->redirect(route('meetups.index', ['country' => str(session('lang_country', config('app.domain_country')))->after('-')->lower()]), navigate: true);
}
public function goToMap(): void
{
$this->redirect(route('meetups.map', ['country' => str(session('lang_country', 'de'))->after('-')->lower()]), navigate: true);
$this->redirect(route('meetups.map', ['country' => str(session('lang_country', config('app.domain_country')))->after('-')->lower()]), navigate: true);
}
}; ?>
@@ -60,7 +60,7 @@ class extends Component {
{{ __('Kartenansicht öffnen') }}
</flux:button>
<flux:button :href="route('dashboard', ['country' => str(session('lang_country', 'de'))->after('-')->lower()])" class="cursor-pointer w-full"
<flux:button :href="route('dashboard', ['country' => str(session('lang_country', config('app.domain_country')))->after('-')->lower()])" class="cursor-pointer w-full"
icon="arrow-right-start-on-rectangle">
{{ __('Login') }}
</flux:button>