diff --git a/public/index.php b/public/index.php index e751d72..d62bb5e 100644 --- a/public/index.php +++ b/public/index.php @@ -1,25 +1,18 @@ translate($key); } -// ----------------------------------------------------------- $url = explode('?', $_SERVER['REQUEST_URI'])[0]; @@ -31,4 +24,4 @@ function translate(string $key): string $controller = $routes[$url][0]; $method = $routes[$url][1]; -(new $controller())->$method(); \ No newline at end of file +(new $controller())->$method(); diff --git a/src/Controller/Translator.php b/src/Controller/Translator.php new file mode 100644 index 0000000..b04cdb8 --- /dev/null +++ b/src/Controller/Translator.php @@ -0,0 +1,33 @@ +translations = include dirname(__DIR__,2). "/translations/{$lang}.php"; + } + + public static function getInstance(): Translator + { + if (self::$instance === null) { + self::$instance = new self(); + } + return self::$instance; + } + + public function translate(string $key): string + { + return $this->translations[$key] ?? $key; + } + + +} \ No newline at end of file