🌐 hacky path based language selection

This commit is contained in:
DrMaxNix 2023-12-31 14:53:20 +01:00
parent ad38ba684b
commit 81afd5e028
3 changed files with 30 additions and 4 deletions

View File

@ -5,6 +5,7 @@
// DEPENDENCIES //
// used extensions
static::$ext[] = "request";
static::$ext[] = "lang";
static::$ext[] = "page";
static::$ext[] = "file";
@ -23,6 +24,7 @@
// pages
static::$route["sbgg.jetzt"] = [
["path" => "", "target" => "page/start"]
["path" => "", "target" => "page/start"],
["path" => ":lang", "target" => "page/start"]
];
?>

View File

@ -1,8 +1,12 @@
<?php
declare(strict_types = 1);
namespace Kimendisch\Selbstbestimmungsgesetzjetztde;
use Flake\Request;
// REDIRECT TO MAIN DOMAIN //
// status code
header("HTTP/1.1 301 Moved Permanently");
// location
header("Location: https://sbgg.jetzt");
header("Location: https://sbgg.jetzt/" . Request::path_full());
?>

View File

@ -8,7 +8,27 @@
use Flake\File;
use Flake\Project;
// HACK: CONVERT GET PARAM TO PATH PARAM //
if(isset($_GET["lang"])){
$new_lang = $_GET["lang"];
if($new_lang === "de") $new_lang = "";
header("HTTP/1.1 303 See Other");
header("Location: /" . $new_lang);
}
// HACK: REMOVE `DE` PATH PARAM //
if(!in_array(Project::param("lang"), [null, "en"])){
header("HTTP/1.1 303 See Other");
header("Location: /");
}
// LANGUAGE MANAGER //
// hack: fake get param from url path
$param_lang = Project::param("lang") ?? "de";
$_GET["lang"] = $param_lang;
// initialize
$lang = new Lang(list: ["de", "en"], default: "de");
@ -406,9 +426,9 @@
<div class="lang">
<span><i class="ti ti-world"></i></span>
<a <?= ($lang->get() === "de" ? "class=\"selected\"" : "") ?> href="?lang=de">DE</a>
<a <?= ($lang->get() === "de" ? "class=\"selected\"" : "") ?> href="/">DE</a>
<span class="delimiter">|</span>
<a <?= ($lang->get() === "en" ? "class=\"selected\"" : "") ?> href="?lang=en">EN</a>
<a <?= ($lang->get() === "en" ? "class=\"selected\"" : "") ?> href="/en">EN</a>
</div>
<div class="legal">