mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-05 12:08:42 +00:00
Improve localization
This commit is contained in:
parent
89c14a69b8
commit
b9a82ea08d
|
|
@ -27,6 +27,7 @@ namespace phpOMS;
|
||||||
* @property \phpOMS\Localization\L11nManager $l11nManager
|
* @property \phpOMS\Localization\L11nManager $l11nManager
|
||||||
* @property \phpOMS\Router\Router $router
|
* @property \phpOMS\Router\Router $router
|
||||||
* @property \phpOMS\DataStorage\Session\SessionInterface $sessionManager
|
* @property \phpOMS\DataStorage\Session\SessionInterface $sessionManager
|
||||||
|
* @property \phpOMS\DataStorage\Cookie\CookieJar $cookieJar
|
||||||
* @property \phpOMS\Module\ModuleManager $moduleManager
|
* @property \phpOMS\Module\ModuleManager $moduleManager
|
||||||
* @property \phpOMS\Dispatcher\Dispatcher $dispatcher
|
* @property \phpOMS\Dispatcher\Dispatcher $dispatcher
|
||||||
* @property \phpOMS\DataStorage\Cache\CachePool $cachePool
|
* @property \phpOMS\DataStorage\Cache\CachePool $cachePool
|
||||||
|
|
@ -123,6 +124,14 @@ class ApplicationAbstract
|
||||||
*/
|
*/
|
||||||
protected $sessionManager = null;
|
protected $sessionManager = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cookie instance.
|
||||||
|
*
|
||||||
|
* @var \phpOMS\DataStorage\Cookie\CookieJar
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected $cookieJar = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server localization.
|
* Server localization.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,20 @@ final class CookieJar
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get cookie value
|
||||||
|
*
|
||||||
|
* @param string $id Cookie id
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function get(string $id)
|
||||||
|
{
|
||||||
|
return $this->cookies[$id] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete already set cookie
|
* Delete already set cookie
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,10 @@ class Localization
|
||||||
throw new InvalidEnumValue($langCode);
|
throw new InvalidEnumValue($langCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($countryCode !== '*' && !\file_exists(__DIR__ . '/../Localization/Defaults/Definitions/' . $langCode . '_' . $countryCode . '.json')) {
|
||||||
|
$countryCode = '*';
|
||||||
|
}
|
||||||
|
|
||||||
$files = \glob(__DIR__ . '/../Localization/Defaults/Definitions/' . $langCode . '_' . $countryCode);
|
$files = \glob(__DIR__ . '/../Localization/Defaults/Definitions/' . $langCode . '_' . $countryCode);
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ final class Request extends RequestAbstract
|
||||||
$this->uri = Http::fromCurrent();
|
$this->uri = Http::fromCurrent();
|
||||||
$this->data = $_GET ?? [];
|
$this->data = $_GET ?? [];
|
||||||
$this->files = $_FILES ?? [];
|
$this->files = $_FILES ?? [];
|
||||||
$this->header->getL11n()->setLanguage($this->loadRequestLanguage());
|
$this->header->getL11n()->setLanguage($this->getRequestLanguage());
|
||||||
|
|
||||||
$this->initNonGetData();
|
$this->initNonGetData();
|
||||||
}
|
}
|
||||||
|
|
@ -155,23 +155,42 @@ final class Request extends RequestAbstract
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load request language
|
* Get request language
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private function loadRequestLanguage() : string
|
public function getRequestLanguage() : string
|
||||||
{
|
{
|
||||||
if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||||
return 'EN';
|
return 'en';
|
||||||
}
|
}
|
||||||
|
|
||||||
$components = \explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
$components = \explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
$locals = \stripos($components[0], ',') !== false ? $locals = \explode(',', $components[0]) : $components;
|
$locals = \stripos($components[0], ',') !== false ? $locals = \explode(',', $components[0]) : $components;
|
||||||
$firstLocalComponents = \explode('-', $locals[0]);
|
$firstLocalComponents = \explode('-', $locals[0]);
|
||||||
|
|
||||||
return $firstLocalComponents[0];
|
return \strtolower($firstLocalComponents[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get request locale
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getLocale() : string
|
||||||
|
{
|
||||||
|
if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||||
|
return 'en_US';
|
||||||
|
}
|
||||||
|
|
||||||
|
$components = \explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
|
$locals = \stripos($components[0], ',') !== false ? $locals = \explode(',', $components[0]) : $components;
|
||||||
|
|
||||||
|
return \str_replace('-', '_', $locals[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -253,7 +272,7 @@ final class Request extends RequestAbstract
|
||||||
$paths[] = $pathArray[$i];
|
$paths[] = $pathArray[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->hash[] = sha1(\implode('', $paths));
|
$this->hash[] = \sha1(\implode('', $paths));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user