forked from veselcraft/FrogFind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalization.php
More file actions
30 lines (23 loc) · 873 Bytes
/
localization.php
File metadata and controls
30 lines (23 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
class UILocale {
protected function parseLang($file): array
{
$string = file_get_contents($file);
$string = preg_replace("%^\%{.*\%}\r?$%m", "", $string); #Remove comments
$array = [];
foreach(preg_split("%;[\\r\\n]++%", $string) as $statement) {
$s = explode(" = ", trim($statement));
try {
$array[eval("return $s[0];")] = eval("return $s[1];");
} catch(\ParseError $ex) {
echo "Could not parse locale :( At " . $s[0];
}
}
return $array;
}
function trRaw($string, $locale) {
$lang = empty($locale) ? "en-us" : $locale;
$array = $this->parseLang(dirname(__FILE__) . "/languages/$lang.strings");
return $array[$string] ?? "@$string";
}
}