Localization & stuff
This commit is contained in:
@@ -6,7 +6,6 @@ use Core\Configuration\Settings;
|
||||
use Core\Driver\Logger\Logger;
|
||||
use Core\Driver\SQL\SQL;
|
||||
use Core\Objects\Context;
|
||||
use Core\Objects\lang\LanguageModule;
|
||||
use Core\Objects\Router\DocumentRoute;
|
||||
use Core\Objects\Router\Router;
|
||||
use Core\Objects\DatabaseEntity\User;
|
||||
@@ -24,6 +23,7 @@ abstract class Document {
|
||||
private array $cspWhitelist;
|
||||
private string $domain;
|
||||
protected bool $searchable;
|
||||
protected array $languageModules;
|
||||
|
||||
public function __construct(Router $router) {
|
||||
$this->router = $router;
|
||||
@@ -34,6 +34,7 @@ abstract class Document {
|
||||
$this->domain = $this->getSettings()->getBaseUrl();
|
||||
$this->logger = new Logger("Document", $this->getSQL());
|
||||
$this->searchable = false;
|
||||
$this->languageModules = [];
|
||||
}
|
||||
|
||||
public abstract function getTitle(): string;
|
||||
@@ -88,11 +89,6 @@ abstract class Document {
|
||||
}
|
||||
}
|
||||
|
||||
public function loadLanguageModule(LanguageModule|string $module) {
|
||||
$language = $this->getContext()->getLanguage();
|
||||
$language->loadModule($module);
|
||||
}
|
||||
|
||||
public function sendHeaders() {
|
||||
if ($this->cspEnabled) {
|
||||
$cspWhiteList = implode(" ", $this->cspWhitelist);
|
||||
@@ -126,8 +122,12 @@ abstract class Document {
|
||||
}
|
||||
}
|
||||
|
||||
$language = $this->getContext()->getLanguage();
|
||||
foreach ($this->languageModules as $module) {
|
||||
$language->loadModule($module);
|
||||
}
|
||||
|
||||
$code = $this->getCode($params);
|
||||
$code = $this->getCode($params);
|
||||
$this->sendHeaders();
|
||||
return $code;
|
||||
}
|
||||
|
||||
@@ -94,6 +94,12 @@ class TemplateDocument extends Document {
|
||||
"csp" => [
|
||||
"nonce" => $this->getCSPNonce(),
|
||||
"enabled" => $this->isCSPEnabled()
|
||||
],
|
||||
"language" => [
|
||||
"code" => $language->getCode(),
|
||||
"shortCode" => $language->getShortCode(),
|
||||
"name" => $language->getName(),
|
||||
"entries" => $language->getEntries()
|
||||
]
|
||||
]
|
||||
], $params);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Core\Elements;
|
||||
|
||||
use Core\Objects\Context;
|
||||
|
||||
abstract class View extends StaticView {
|
||||
|
||||
private Document $document;
|
||||
@@ -18,9 +20,10 @@ abstract class View extends StaticView {
|
||||
|
||||
public function getTitle(): string { return $this->title; }
|
||||
public function getDocument(): Document { return $this->document; }
|
||||
public function getContext(): Context { return $this->document->getContext(); }
|
||||
|
||||
public function getSiteName(): string {
|
||||
return $this->getDocument()->getSettings()->getSiteName();
|
||||
return $this->getContext()->getSettings()->getSiteName();
|
||||
}
|
||||
|
||||
protected function load(string $viewClass) : string {
|
||||
@@ -38,23 +41,13 @@ abstract class View extends StaticView {
|
||||
return "";
|
||||
}
|
||||
|
||||
private function loadLanguageModules() {
|
||||
$lang = $this->document->getContext()->getLanguage();
|
||||
foreach ($this->langModules as $langModule) {
|
||||
$lang->loadModule($langModule);
|
||||
}
|
||||
}
|
||||
|
||||
// Virtual Methods
|
||||
public function loadView() { }
|
||||
|
||||
public function getCode(): string {
|
||||
|
||||
// Load translations
|
||||
$this->loadLanguageModules();
|
||||
|
||||
// Load metadata + head (title, scripts, includes, ...)
|
||||
if($this->loadView) {
|
||||
if ($this->loadView) {
|
||||
$this->loadView();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user