Added support for lang (localized strings)
This commit is contained in:
parent
35145b9677
commit
873bfbf6fe
|
@ -1,7 +1,36 @@
|
|||
<?php
|
||||
|
||||
function s($name) {
|
||||
echo $name;
|
||||
function strings() {
|
||||
$lang = client_lang();
|
||||
if (isset($GLOBALS['lang_'.$lang]))
|
||||
return $GLOBALS['lang_'.$lang];
|
||||
$file = 'config/lang/'.$lang.'.php';
|
||||
if (!file_exists($file))
|
||||
return [];
|
||||
require_once $file;
|
||||
if (!isset($strings))
|
||||
return [];
|
||||
$GLOBALS['lang_'.$lang] = $strings;
|
||||
return $strings;
|
||||
}
|
||||
|
||||
function s($name, $return=false) {
|
||||
$strings = strings();
|
||||
$key = "['".str_replace('.', "']['", $name)."']";
|
||||
$val = eval('echo $strings'.$key.' ?? $name;');
|
||||
if ($return)
|
||||
return $val;
|
||||
echo $val;
|
||||
}
|
||||
|
||||
function client_lang() {
|
||||
if (!isset($GLOBALS['cfg_lang'])) {
|
||||
require_once 'config/lang.php';
|
||||
$GLOBALS['cfg_lang'] = [ $default_lang, $supported_langs ];
|
||||
}
|
||||
$lang = substr(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']), 0, 2);
|
||||
return in_array($lang, $GLOBALS['cfg_lang'][1]) ?
|
||||
$lang : $GLOBALS['cfg_lang'][0];
|
||||
}
|
||||
|
||||
function urlargs($from = 0) {
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
$default_lang = 'en';
|
||||
$supported_langs = [
|
||||
'en',
|
||||
'es',
|
||||
];
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
$strings = [
|
||||
|
||||
];
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
$strings = [
|
||||
|
||||
];
|
Loading…
Reference in New Issue