-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanguageManager.php
More file actions
48 lines (40 loc) · 1.62 KB
/
LanguageManager.php
File metadata and controls
48 lines (40 loc) · 1.62 KB
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
<?php
class LanguageManager{
private $file;
private $lang;
private $language;
//private $configData;
private $availableLanguage = array("francais", "english");
function __construct(){
$this->file = "../config";
$content = file($this->file);
foreach($content as $line){
if(str_starts_with($line, "lang=")){
$this->language = str_replace("lang=", "", $line);
break;
}
}
if($this->language == null){die("Invalid configuration");}
if(!array_key_exists($this->language, $this->availableLanguage)){$this->setLanguage("english");}
$this->lang = json_decode(file_get_contents('lang/' . $this->language . ".json"), true);
/*$this->configData = json_decode(file_get_contents('../config.json'),true);
if(!isset($this->configData["lang"])){die("Invalid Config");}*/
}
public function getFromLang(string $parameter):string {
return (isset($this->lang[$parameter]) ? $this->lang[$parameter] : "non-defined");
}
public function setLanguage(string $language):void{
if(!array_key_exists($language, $this->availableLanguage)){return;}
$content = file($this->file);
for($i = 0 ; $i < count($content) ; $i++){
if(str_starts_with($content[$i], "lang=")){
$content[$i] = "lang=" . $language;
break;
}
}
file_put_contents($this->file, $content);
$this->language = $language;
$this->lang = json_decode(file_get_contents('lang/' . $this->language . ".json"), true);
}
}
?>