Initial commit of the complete City10 virtual city simulation platform. Backend (Laravel 13): - REST API with Sanctum tokens and session-based web authentication - Role-based access control (admin/user) with middleware protection - AI agent CRUD with OpenRouter.ai integration restricted to free models - Store management with 3D coordinates and AI shopkeeper assignment - Versioned legal documents (Terms, Privacy, Cookies) with LGPD audit trail - Math CAPTCHA on public forms and multi-language support (pt_BR, en, es) Frontend: - Responsive Blade templates with Tailwind CSS v4 - Three.js 3D city viewer with SSE chat streaming to AI agents - Admin panel for store and user administration Infrastructure: - MariaDB/MySQL database with comprehensive migrations - Database seeders for demo content and test accounts - PHPUnit test suite and Laravel Pint code styling - Vite build configuration with hot reload
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?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);
|
|
}
|
|
}
|