mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
Optimized language display
Language is no longer passed in "10" different ways.
This commit is contained in:
parent
c78d535ef6
commit
486ac07eea
|
|
@ -58,9 +58,9 @@ class L11nManager
|
|||
* One module can only be loaded once. Once the module got loaded it's not
|
||||
* possible to load more language files later on.
|
||||
*
|
||||
* @param string $language Language iso code
|
||||
* @param string $from Module name
|
||||
* @param string[][] $files Language files content
|
||||
* @param string $language Language iso code
|
||||
* @param string $from Module name
|
||||
* @param string[][] $translation Language files content
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
@ -69,17 +69,17 @@ class L11nManager
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function loadLanguage(string $language, string $from, array $files)
|
||||
public function loadLanguage(string $language, string $from, array $translation)
|
||||
{
|
||||
if (!isset($files[$from])) {
|
||||
if (!isset($translation[$from])) {
|
||||
throw new \Exception('Unexpected language key: ' . $from);
|
||||
}
|
||||
|
||||
if (!isset($this->language[$language][$from])) {
|
||||
$this->language[$language][$from] = $files[$from];
|
||||
$this->language[$language][$from] = $translation[$from];
|
||||
} else {
|
||||
/** @noinspection PhpWrongStringConcatenationInspection */
|
||||
$this->language[$language][$from] = $files[$from] + $this->language[$language][$from];
|
||||
$this->language[$language][$from] = $translation[$from] + $this->language[$language][$from];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -104,4 +104,21 @@ class L11nManager
|
|||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translation.
|
||||
*
|
||||
* @param string $code Country code
|
||||
* @param string $module Module name
|
||||
* @param string $translation Text
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getText(string $code, string $module, string $translation)
|
||||
{
|
||||
return $this->language[$code][$module][$translation] ?? 'ERROR';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
* @link http://orange-management.com
|
||||
*/
|
||||
namespace phpOMS\Localization;
|
||||
|
||||
use phpOMS\Datatypes\Exception\InvalidEnumValue;
|
||||
|
||||
/**
|
||||
|
|
@ -87,21 +88,24 @@ class Localization
|
|||
private $datetime = 'Y-m-d H:i:s';
|
||||
|
||||
/**
|
||||
* Language array.
|
||||
* Localization manager.
|
||||
*
|
||||
* @var string[]
|
||||
* @var L11nManager
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public $lang = [];
|
||||
public $l11nManager = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param L11nManager $l11nManager Localization manager
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(L11nManager $l11nManager)
|
||||
{
|
||||
$this->l11nManager = $l11nManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -146,7 +150,7 @@ class Localization
|
|||
/**
|
||||
* @param string $timezone
|
||||
*
|
||||
* @todo: maybe make parameter int
|
||||
* @todo : maybe make parameter int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
|
|
@ -188,30 +192,6 @@ class Localization
|
|||
$this->language = $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getLang() : array
|
||||
{
|
||||
return $this->lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $lang
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function setLang(array $lang)
|
||||
{
|
||||
$this->lang = $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
|
|
@ -311,4 +291,20 @@ class Localization
|
|||
{
|
||||
$this->thousands = $thousands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translation.
|
||||
*
|
||||
* @param string $module Module name
|
||||
* @param string $translation Text
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getText(string $module, string $translation)
|
||||
{
|
||||
return $this->l11nManager->getText($this->language, $module, $translation);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
$CORELANG[0] = [
|
||||
'Add' => 'Add',
|
||||
'Cancel' => 'Cancel',
|
||||
'Close' => 'Close',
|
||||
'Create' => 'Create',
|
||||
'Delete' => 'Delete',
|
||||
'Edit' => 'Edit',
|
||||
'Email' => 'Email',
|
||||
'Empty' => 'Empty',
|
||||
'Filter' => 'Filter',
|
||||
'Find' => 'Find',
|
||||
'ID' => 'ID',
|
||||
'More' => 'More',
|
||||
'Navigation' => 'Navigation',
|
||||
'Password' => 'Password',
|
||||
'Reset' => 'Reset',
|
||||
'Save' => 'Save',
|
||||
'Search' => 'Search',
|
||||
'Select' => 'Select',
|
||||
'Send' => 'Send',
|
||||
'Submit' => 'Submit',
|
||||
'e:empty' => "This field mustn't be empty.",
|
||||
'Monday' => 'Monday',
|
||||
'Tuesday' => 'Tuesday',
|
||||
'Wednesday' => 'Wednesday',
|
||||
'Thursday' => 'Thursday',
|
||||
'Friday' => 'Friday',
|
||||
'Saturday' => 'Saturday',
|
||||
'Sunday' => 'Sunday',
|
||||
];
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
namespace phpOMS\Message\Http;
|
||||
|
||||
use phpOMS\Localization\L11nManager;
|
||||
use phpOMS\Localization\Localization;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Uri\Http;
|
||||
|
|
@ -87,15 +88,16 @@ class Request extends RequestAbstract
|
|||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param UriInterface $uri Uri
|
||||
* @param L11nManager $l11nManager Localization manager
|
||||
* @param UriInterface $uri Uri
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(UriInterface $uri = null)
|
||||
public function __construct(L11nManager $l11nManager, UriInterface $uri = null)
|
||||
{
|
||||
$this->l11n = new Localization($l11nManager);
|
||||
$this->uri = $uri;
|
||||
$this->l11n = new Localization();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
namespace phpOMS\Message\Http;
|
||||
|
||||
use phpOMS\Localization\L11nManager;
|
||||
use phpOMS\Localization\Localization;
|
||||
use phpOMS\System\MimeType;
|
||||
use phpOMS\Contract\RenderableInterface;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
|
|
@ -36,12 +38,15 @@ class Response extends ResponseAbstract implements RenderableInterface
|
|||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param L11nManager $l11nManager Localization manager
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(L11nManager $l11nManager)
|
||||
{
|
||||
$this->header = new Header();
|
||||
$this->l11n = new Localization($l11nManager);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -277,14 +277,6 @@ abstract class RequestAbstract implements MessageInterface
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setLocalization(Localization $l11n)
|
||||
{
|
||||
return $this->l11n = $l11n;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -80,14 +80,6 @@ abstract class ResponseAbstract implements MessageInterface
|
|||
return $this->l11n;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setL11n(Localization $l11n)
|
||||
{
|
||||
return $this->l11n = $l11n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get response by ID.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -99,6 +99,38 @@ class InstallerAbstract
|
|||
public static function install(Pool $dbPool, InfoManager $info)
|
||||
{
|
||||
self::registerInDatabase($dbPool, $info);
|
||||
self::initRoutes($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-init module.
|
||||
*
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function reInit(InfoManager $info)
|
||||
{
|
||||
self::initRoutes($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init routes.
|
||||
*
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws PermissionException
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private static function initRoutes(InfoManager $info)
|
||||
{
|
||||
self::installRoutes(ROOT_PATH . '/Web/Routes.php', ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes/http.php');
|
||||
self::installRoutes(ROOT_PATH . '/Socket/Routes.php', ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes/socket.php');
|
||||
self::installRoutes(ROOT_PATH . '/Console/Routes.php', ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes/console.php');
|
||||
|
|
|
|||
|
|
@ -346,6 +346,37 @@ class ModuleManager
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-init module.
|
||||
*
|
||||
* @param string $module Module name
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
public function reInit(string $module) : bool
|
||||
{
|
||||
if(file_exists($path = __DIR__ . '/../Web/Routes.php')) {
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
file_put_contents($path, '<?php return [];');
|
||||
|
||||
$info = $this->loadInfo($module);
|
||||
/** @var $class InstallerAbstract */
|
||||
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer';
|
||||
|
||||
if (!Autoloader::exists($class)) {
|
||||
throw new \Exception('Module installer does not exist');
|
||||
}
|
||||
|
||||
$class::reInit($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Install module.
|
||||
*
|
||||
|
|
@ -569,13 +600,11 @@ class ModuleManager
|
|||
*/
|
||||
public function initModule($module)
|
||||
{
|
||||
if (is_array($module)) {
|
||||
$this->initModuleArray($module);
|
||||
} elseif (is_string($module) && realpath(self::MODULE_PATH . '/' . $module . '/Controller.php') !== false) {
|
||||
$this->initModuleController($module);
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Invalid Module');
|
||||
if(!is_array($module)) {
|
||||
$module = [$module];
|
||||
}
|
||||
|
||||
$this->initModuleArray($module);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -592,7 +621,7 @@ class ModuleManager
|
|||
{
|
||||
foreach ($modules as $module) {
|
||||
try {
|
||||
$this->initModule($module);
|
||||
$this->initModuleController($module);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->app->logger->warning(FileLogger::MSG_FULL, [
|
||||
'message' => 'Trying to initialize ' . $module . ' without controller.',
|
||||
|
|
|
|||
|
|
@ -107,8 +107,7 @@ class View implements \Serializable
|
|||
$this->app = $app;
|
||||
$this->request = $request;
|
||||
$this->response = $response;
|
||||
|
||||
$this->l11n = new Localization();
|
||||
$this->l11n = $response->getL11n();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -259,7 +258,6 @@ class View implements \Serializable
|
|||
*/
|
||||
public function render() : string
|
||||
{
|
||||
$this->l11n->setLang($this->app->l11nManager->getLanguage($this->response->getL11n()->getLanguage()));
|
||||
$path = realpath($oldPath = __DIR__ . '/../..' . $this->template . '.tpl.php');
|
||||
|
||||
if ($path === false || Validator::startsWith($path, ROOT_PATH) === false) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user