From 1fff9acded106f2e7846c8a872abd8f6f56506df Mon Sep 17 00:00:00 2001 From: David Amorim Date: Thu, 18 Apr 2024 16:23:55 -0300 Subject: [PATCH] =?UTF-8?q?(Patterns=20Singleton)=3D>=20Padr=C3=A3o=20impl?= =?UTF-8?q?ementado=20para=20trabalhar=20as=20tradu=C3=A7=C3=B5es=20da=20a?= =?UTF-8?q?plica=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.php | 19 ++++++------------- src/Controller/Translator.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 src/Controller/Translator.php 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