Commit 5c0685e8 authored by M.Nowocyn's avatar M.Nowocyn

Fixed a bug, that made the Language system unavailable and doesn't support the user set language.

parent c0a23469
<?php
/**
* Created by PhpStorm.
* User: Matze
* Date: 26.07.2017
* Time: 22:07
*/
namespace Iko;
use Iko\Language\Key;
use Iko\Language\Language;
use Iko\Language\System;
header("Access-Control-Allow-Origin: *");
$status = false;
$key = $_REQUEST['key'] ?? "";
$text = "";
$lang = $_REQUEST['lang'] ?? "";
System::getInstance($lang);
$text = Key::getString($key);
$return = array (
"status" => $status,
"key" => $key,
"lang" => $lang,
"text" => $text);
echo json_encode($return);
......@@ -21,7 +21,33 @@ class Language extends Mixed implements iLanguage
{
protected static $cache;
protected static $cache_exist;
private $status;
public static function get ($id = 0, $reload = false): iLanguage
{
$return = parent::get(
$id,
$reload
);
if (!$return instanceof iLanguage) {
$return = new class() implements iLanguage
{
public function getName (): string
{
return "";
}
public function __toString ()
{
return "undefined";
}
};
}
return $return;
}
private $status;
private $language;
protected function __construct ( string $lang )
......
......@@ -38,7 +38,7 @@ class System extends Instance implements iSystem
"english" );
protected static $instance = NULL;
public static function getInstance ( $args = NULL ): System
public static function getInstance ($args = null): iSystem
{
return parent::getInstance( $args );
}
......@@ -47,19 +47,24 @@ class System extends Instance implements iSystem
private $current = NULL;
private $languages = array ();
protected function __construct ()
{
$lang = NULL;
if ( Session::isLoggedIn() ) {
$lang = User::getSession()->getLanguage();
}
if ( $lang == NULL || $lang == "" ) {
$this->config = Config::load(
"pdo",
"language"
);
$lang = $this->config->default_language ?? self::DEFAULT;
}
protected function __construct ($args)
{
if ($args !== NULL && Language::exist($args)) {
$lang = $args;
}
else {
$lang = null;
if (Session::isLoggedIn()) {
$lang = User::getSession()->getLanguage();
}
if ($lang == null || $lang == "") {
$this->config = Config::load(
"pdo",
"language"
);
$lang = $this->config->default_language ?? self::DEFAULT;
}
}
$this->current = Language::get( $lang );
$sql = "SHOW COLUMNS FROM " . self::TABLE;
......
......@@ -16,4 +16,6 @@ interface iLanguage
const GET = "getName";
public function getName (): string;
public function __toString ();
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment