mirror of https://github.com/byecorps/id.git
Add basic translation support
This commit is contained in:
parent
2cd1b012ac
commit
76c96d3a1c
|
@ -0,0 +1,4 @@
|
|||
[submodule "strings"]
|
||||
path = strings
|
||||
branch = main
|
||||
url = https://github.com/byecorps/id-strings
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
function get_string($key="generic.generic") {
|
||||
global $LANG;
|
||||
|
||||
$key_path = explode('.', $key);
|
||||
|
||||
$result = $LANG;
|
||||
|
||||
foreach ($key_path as $k) {
|
||||
if (isset($result[$k])) {
|
||||
$result = $result[$k];
|
||||
} else {
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function patch_lang($lang="en") {
|
||||
|
||||
global $LANG, $DOC_ROOT;
|
||||
|
||||
$temp = $LANG;
|
||||
|
||||
if (file_exists("$DOC_ROOT/strings/$lang.php")) {
|
||||
require_once("$DOC_ROOT/strings/$lang.php");
|
||||
}
|
||||
|
||||
function merge_arrays($original, $new) {
|
||||
foreach ($new as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
if (!isset($original[$key])) {
|
||||
$original[$key] = [];
|
||||
}
|
||||
$original[$key] = merge_arrays($original[$key], $value);
|
||||
} else {
|
||||
// Replace only if the value is not blank
|
||||
if ($value !== '') {
|
||||
$original[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $original;
|
||||
}
|
||||
|
||||
$LANG = merge_arrays($temp, $LANG);
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 2ca0a987728cf7c90454eab06083f49442109eb5
|
Loading…
Reference in New Issue