feat(i18n): translation files DE/EN/UK/RU + layout integration (closes #74)

This commit is contained in:
Hermes
2026-06-04 09:31:34 +00:00
parent ce21242308
commit 4b1c779846
14 changed files with 1799 additions and 850 deletions

View File

@@ -4,8 +4,14 @@ declare(strict_types=1);
namespace App\Controllers;
use App\Core\I18n;
use App\Core\Locale;
use App\Core\View;
/**
* Base controller — injects i18n globals (locale, t() helper, locale switcher)
* into every render() call so views can use `$t('key')` and `$locale` directly.
*/
abstract class Controller
{
protected View $view;
@@ -15,9 +21,28 @@ abstract class Controller
$this->view = new View();
}
/**
* Render a view inside a layout.
*
* @param array<string,mixed> $data
*/
protected function render(string $view, array $data = [], string $layout = 'main'): void
{
foreach ($data as $key => $value) {
$locale = LocaleController::current();
$i18n = static fn (string $key, array $params = []): string => I18n::t($key, $params, $locale);
$globals = [
'locale' => $locale,
't' => $i18n,
'locale_switcher' => static function (string $currentPath) use ($locale): string {
$switcher = new LocaleSwitcher($locale, $currentPath);
return $switcher->render();
},
];
$merged = array_merge($globals, $data);
foreach ($merged as $key => $value) {
$this->view->assign($key, $value);
}
$this->view->render($view, $layout);