PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
InstallerLang.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\wizard;
23 
24 
26  public static $languages = [
27  "en" => "English",
28  "es" => "Español",
29  "zh" => "中文",
30  "ru" => "Pyccĸий",
31  "ja" => "日本語",
32  "de" => "Deutsch",
33  //"vi" => "Tiếng Việt",
34  "ko" => "한국어",
35  "nl" => "Nederlands",
36  "fr" => "Français",
37  "it" => "Italiano",
38  //"lv" => "Latviešu",
39  "ms" => "Melayu",
40  "no" => "Norsk",
41  //"pt" => "Português",
42  "sv" => "Svenska",
43  "fi" => "Suomi",
44  "tr" => "Türkçe",
45  //"et" => "Eesti",
46  ];
47  private $texts = [];
48  private $lang;
49  private $langfile;
50 
51  public function __construct($lang = ""){
52  if(file_exists(\pocketmine\PATH . "src/pocketmine/lang/Installer/" . $lang . ".ini")){
53  $this->lang = $lang;
54  $this->langfile = \pocketmine\PATH . "src/pocketmine/lang/Installer/" . $lang . ".ini";
55  }else{
56  $files = [];
57  foreach(new \DirectoryIterator(\pocketmine\PATH . "src/pocketmine/lang/Installer/") as $file){
58  if($file->getExtension() === "ini" and substr($file->getFilename(), 0, 2) === $lang){
59  $files[$file->getFilename()] = $file->getSize();
60  }
61  }
62 
63  if(count($files) > 0){
64  arsort($files);
65  reset($files);
66  $l = key($files);
67  $l = substr($l, 0, -4);
68  $this->lang = isset(self::$languages[$l]) ? $l : $lang;
69  $this->langfile = \pocketmine\PATH . "src/pocketmine/lang/Installer/" . $l . ".ini";
70  }else{
71  $this->lang = "en";
72  $this->langfile = \pocketmine\PATH . "src/pocketmine/lang/Installer/en.ini";
73  }
74  }
75 
76  $this->loadLang(\pocketmine\PATH . "src/pocketmine/lang/Installer/en.ini", "en");
77  if($this->lang !== "en"){
78  $this->loadLang($this->langfile, $this->lang);
79  }
80 
81  }
82 
83  public function getLang(){
84  return ($this->lang);
85  }
86 
87  public function loadLang($langfile, $lang = "en"){
88  $this->texts[$lang] = [];
89  $texts = explode("\n", str_replace(["\r", "\\/\\/"], ["", "//"], file_get_contents($langfile)));
90  foreach($texts as $line){
91  $line = trim($line);
92  if($line === ""){
93  continue;
94  }
95  $line = explode("=", $line);
96  $this->texts[$lang][trim(array_shift($line))] = trim(str_replace(["\\n", "\\N",], "\n", implode("=", $line)));
97  }
98  }
99 
100  public function get($name, $search = [], $replace = []){
101  if(!isset($this->texts[$this->lang][$name])){
102  if($this->lang !== "en" and isset($this->texts["en"][$name])){
103  return $this->texts["en"][$name];
104  }else{
105  return $name;
106  }
107  }elseif(count($search) > 0){
108  return str_replace($search, $replace, $this->texts[$this->lang][$name]);
109  }else{
110  return $this->texts[$this->lang][$name];
111  }
112  }
113 
114  public function __get($name){
115  return $this->get($name);
116  }
117 
118 }