From 91f6dd2a8bc6e9c29b4fbf34c7723413db5a2f31 Mon Sep 17 00:00:00 2001 From: Bastard Operator Date: Thu, 25 Nov 2021 01:01:05 +0100 Subject: [PATCH] Implemented locale system (without lang detection) --- src/base.php | 17 +++++++++++++++++ src/locales/es.json | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/locales/es.json diff --git a/src/base.php b/src/base.php index b7972f1..f5906c9 100644 --- a/src/base.php +++ b/src/base.php @@ -4,3 +4,20 @@ $env = 'prod'; if (getenv('ENV') !== false && in_array(getenv('ENV'), ['prod', 'dev'])) $env = getenv('ENV'); define('ENV', $env); + + +# load locales +$lang = 'es'; +$lang_file = '/src/locales/'.$lang.'.json'; +$locales = (object)[]; +if (file_exists($lang_file)) + $locales = json_decode(file_get_contents($lang_file), true); +$locales; + +function l($key, $default='') { + global $locales; + $parts = explode('.', $key); + if (isset($locales[$parts[0]][$parts[1]])) + echo $locales[$parts[0]][$parts[1]]; + else echo $default; +} diff --git a/src/locales/es.json b/src/locales/es.json new file mode 100644 index 0000000..9c187d9 --- /dev/null +++ b/src/locales/es.json @@ -0,0 +1,11 @@ +{ + "all": { + "app_name": "RealFan", + "_": "" + }, + "home": { + "register": "RegĂ­strate", + "_": "" + }, + "_": "" +}