From 18e7955b12a05a115d644b9da4876420947ae9e9 Mon Sep 17 00:00:00 2001 From: Roman Date: Sat, 3 Apr 2021 10:39:13 +0200 Subject: [PATCH] Readme, some fixes, rel noopener for _blank links --- README.md | 44 +++++++++++++++++++++++++++++++- adminPanel/src/sidebar.js | 2 +- adminPanel/src/views/help.js | 8 +++++- adminPanel/src/views/settings.js | 2 +- core/Elements/Document.class.php | 11 +++++--- core/Elements/View.class.php | 2 +- core/Objects/ApiObject.class.php | 2 +- core/Objects/Language.class.php | 9 ++++--- core/Objects/Session.class.php | 10 ++++---- core/core.php | 10 ++++---- index.php | 7 +++-- js/admin.min.js | 2 +- 12 files changed, 82 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 218ec0c..90fef4e 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ namespace Documents\Example { } public function getCode(): string { - $view = $this->getDocument()->getView() ?? ""; + $view = $this->getDocument()->getRequestedView() ?? ""; return "Requested View: " . htmlspecialchars($view); } } @@ -223,6 +223,48 @@ namespace Documents\Example { Of course, the head and body classes can be placed in any file, as the code might get big and complex. +### Localization + +Currently, there are two languages specified, which are stored in the database: `en_US` and `de_DE`. +A language is dynamically loaded according to the sent `Accept-Language`-Header, but can also be set using the `lang` parameter +or [/api/language/set](/core/Api/LanguageAPI.class.php) endpoint. Localization of strings can be achieved using the [LanguageModule](/core/Objects/lang/LanguageModule.php)-Class. +Let's look at this example: + +```php +class ExampleLangModule extends \Objects\lang\LanguageModule { + public function getEntries(string $langCode) { + $entries = array(); + switch ($langCode) { + case 'de_DE': + $entries["EXAMPLE_KEY"] = "Das ist eine Beispielübersetzung"; + $entries["Welcome"] = "Willkommen"; + break; + default: + $entries["EXAMPLE_KEY"] = "This is an example translation"; + break; + } + return $entries; + } +} +``` + +If any translation key is not defined, the key is returned, which means, we don't need to specify the string `Welcome` again. To access the translations, +we firstly have to load the module. This is done by adding the class, or the object inside the constructor. +To translate the defined strings, we can use the global `L()` function. The following code snipped shows the use of +our sample language module: + +```php +class SomeView extends \Elements\View { + public function __construct(\Elements\Document $document) { + parent::__construct($document); + $this->langModules[] = ExampleModule::class; + } + + public function getCode() : string{ + return L("Welcome") . "! " . L("EXAMPLE_KEY"); + } +} +``` ## Anything more? diff --git a/adminPanel/src/sidebar.js b/adminPanel/src/sidebar.js index 108021a..69c4ec7 100644 --- a/adminPanel/src/sidebar.js +++ b/adminPanel/src/sidebar.js @@ -75,7 +75,7 @@ export default function Sidebar(props) { let filePath = parent.filesPath; if (filePath) { li.push(
  • - +

    Files

    diff --git a/adminPanel/src/views/help.js b/adminPanel/src/views/help.js index fc92200..0b2d439 100644 --- a/adminPanel/src/views/help.js +++ b/adminPanel/src/views/help.js @@ -121,7 +121,13 @@ export default function HelpPage() { Project Lead & Main Developer diff --git a/adminPanel/src/views/settings.js b/adminPanel/src/views/settings.js index 9f2dd7f..d48312a 100644 --- a/adminPanel/src/views/settings.js +++ b/adminPanel/src/views/settings.js @@ -422,7 +422,7 @@ export default class Settings extends React.Component {