Add multilingual support (DE default, EN under /en/)

This commit is contained in:
chriz committed 2026-10-23 13:06:56 +02:00
1 parent 01ea3bd07a
commit 1e33c525f1
21 files changed
+855 -443

No files matched your search

+32 -2
View File
@@ -1,8 +1,38 @@
<?php
class Helper {
public static function parseHolidays($config) {
$text = $config['holidays']['text'];
private static $currentLang = 'de';
public static function setLang($lang) {
self::$currentLang = ($lang === 'en') ? 'en' : 'de';
}
public static function getLang() {
return self::$currentLang;
}
/**
* Build a language-aware internal URL.
* German (default): / or /leistungen.html
* English: /en/ or /en/leistungen.html
*/
public static function url($path = '/', $lang = null) {
$targetLang = $lang !== null ? $lang : self::$currentLang;
$cleanPath = '/' . ltrim($path, '/');
if ($cleanPath === '/index.php' || $cleanPath === '/main.html') {
$cleanPath = '/';
}
if ($targetLang === 'en') {
return $cleanPath === '/' ? '/en/' : '/en' . $cleanPath;
}
return $cleanPath;
}
public static function parseHolidays($config, $lang = null) {
$targetLang = $lang !== null ? $lang : self::$currentLang;
$text = ($targetLang === 'en' && !empty($config['holidays']['text_en']))
? $config['holidays']['text_en']
: $config['holidays']['text'];
$from = DateTime::createFromFormat('Y-m-d', $config['holidays']['from']);
$until = DateTime::createFromFormat('Y-m-d', $config['holidays']['until']);
$text = preg_replace('/\{\{from\}\}/', $from->format('d.m.Y'), $text);