Files
City10/app/Http/Middleware/SetLocale.php
T
marcocosta10000 79ce2a1825 feat(world): add persistent citizen simulation with needs, jobs, and social features
- Adds Character model with survival needs (hunger, thirst, energy) and state machine
- Implements city:tick world ticker for offline progression every minute
- Adds city territory expansion and building construction system
- Introduces job economy, inventory, and transaction audit trail
- Adds social graph (friends, marriage, children) and character chat
- Implements admin approval workflow for new registrations
- Adds hospital admission system for traffic accidents
- Includes comprehensive feature tests and world seeders
2026-10-17 21:46:23 -03:00

44 lines
1.1 KiB
PHP
Executable File

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Symfony\Component\HttpFoundation\Response;
/**
* Applies the visitor's preferred locale on each request.
*
* Reads the locale from the session (set at login or when the user switches
* language) or from the city10-locale cookie, falling back to the default.
* This keeps the whole interface in the language chosen by the user.
*/
class SetLocale
{
/**
* Supported UI locales.
*
* @var list<string>
*/
public const SUPPORTED = ['pt_BR', 'en', 'es'];
/**
* Handle an incoming request.
*
* @param Closure(Request): (Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$locale = ($request->hasSession() ? $request->session()->get('locale') : null)
?: $request->cookie('city10-locale')
?: config('app.locale');
if (in_array($locale, self::SUPPORTED, true)) {
App::setLocale($locale);
}
return $next($request);
}
}