-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLang.class.php
67 lines (55 loc) · 1.52 KB
/
Lang.class.php
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
if(isset($_SESSION['lang'])) {
Lang::setLanguage($_SESSION['lang']);
}
class Lang
{
private static $lang = null;
private static $lock = false;
private static $language = "de";
static public function setLanguage($l) {
self::$language = $l;
}
static public function getLanguage() {
return self::$language;
}
static public function txt($orig) {
if(self::$language == "de") {
return $orig;
}
while(self::$lock) { sleep(1); }
self::$lock = true;
if(self::$language == "pt") {
$lang_file = "lang_pt.csv";
} elseif(self::$language == "fr") {
$lang_file = "lang_fr.csv";
} elseif(self::$language == "hu") {
$lang_file = "lang_hu.csv";
} else {
$lang_file = "lang_en.csv";
}
if(self::$lang == null) {
self::$lang = Array();
foreach(explode("\n", file_get_contents($lang_file)) as $line) {
if(strpos($line, "#") === 0) { continue; }
@list($from, $to) = explode("|", $line);
$from = str_replace("|", "|", $from);
$from = str_replace("<br>", "\n", $from);
$to = str_replace("|", "|", $to);
$to = str_replace("<br>", "\n", $to);
self::$lang[$from] = $to;
}
}
if(!isset(self::$lang[$orig])) {
$orig1 = str_replace("|", "|", $orig);
$orig1 = str_replace("\n", "<br>", $orig1);
file_put_contents($lang_file, $orig1."|\n", FILE_APPEND);
self::$lang[$orig] = "";
}
self::$lock = false;
if(isset(self::$lang[$orig]) && self::$lang[$orig]!=="") {
return self::$lang[$orig];
}
return $orig;
}
}