44 lines
1.4 KiB
PHP
Executable File
44 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
// --- Application Configuration ---
|
|
const APP_NAME = 'Collections';
|
|
const DB_PATH = __DIR__ . '/collections.sqlite';
|
|
const DEFAULT_LOCALE = 'nl';
|
|
const SUPPORTED_LOCALES = ['nl', 'en'];
|
|
|
|
// --- Session Start ---
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
|
|
// De autoloader moet geladen zijn voordat we hier komen.
|
|
// Gebruik FQCNs om afhankelijkheid van 'use' statements te vermijden.
|
|
|
|
// --- Twig Setup ---
|
|
$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/templates');
|
|
$twig = new \Twig\Environment($loader, [
|
|
// 'cache' => __DIR__ . '/cache/twig', // Uncomment for production
|
|
'debug' => true,
|
|
]);
|
|
|
|
// --- Translation Setup ---
|
|
$translationService = new \App\Services\TranslationService(
|
|
__DIR__ . '/lang',
|
|
SUPPORTED_LOCALES,
|
|
DEFAULT_LOCALE
|
|
);
|
|
|
|
// Get current locale from session or default
|
|
$locale = $_SESSION['locale'] ?? DEFAULT_LOCALE;
|
|
$translator = $translationService->getTranslator($locale);
|
|
|
|
// Add translation function to Twig
|
|
$twig->addFunction(new \Twig\TwigFunction('trans', function (string $id, array $parameters = [], string $domain = null, string $locale = null) use ($translator) {
|
|
return $translator->trans($id, $parameters, $domain, $locale);
|
|
}));
|
|
|
|
// Add current locale to Twig globals
|
|
$twig->addGlobal('current_locale', $locale);
|
|
$twig->addGlobal('supported_locales', SUPPORTED_LOCALES);
|
|
$twig->addGlobal('app_name', APP_NAME);
|