Implemented locale system (without lang detection)

This commit is contained in:
Bofh 2021-11-25 01:01:05 +01:00
parent adda2114e5
commit 91f6dd2a8b
2 changed files with 28 additions and 0 deletions

View File

@ -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;
}

11
src/locales/es.json Normal file
View File

@ -0,0 +1,11 @@
{
"all": {
"app_name": "RealFan",
"_": ""
},
"home": {
"register": "Regístrate",
"_": ""
},
"_": ""
}