Files
City10/app/Http/Controllers/Web/LanguageController.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

52 lines
1.5 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
/**
* Language switcher controller.
*
* Persists the selected locale (pt_BR, en, es) in the session and in the
* user's profile when authenticated, so the whole UI is rendered in the
* language chosen from the dashboard or the public pages.
*/
class LanguageController extends Controller
{
/**
* Switch the application locale for the current visitor.
*/
public function switch(Request $request): RedirectResponse
{
$locale = $request->input('locale');
if (! in_array($locale, ['pt_BR', 'en', 'es'], true)) {
return back();
}
App::setLocale($locale);
$request->session()->put('locale', $locale);
if ($user = $request->user()) {
$user->update(['locale' => $locale]);
}
// Persist the cookie preference (1 year) used on subsequent visits.
$response = back();
$previousPath = (string) parse_url($response->getTargetUrl(), PHP_URL_PATH);
// The 3D viewer fetches /city/data via XHR, which can become the
// session's "previous URL" and would dump the user on raw JSON.
if ($previousPath === '/city/data') {
$response = redirect()->route('city.viewer');
}
$response->withCookie(cookie('city10-locale', $locale, 60 * 24 * 365, '/', null, false, true));
return $response;
}
}