GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
InstallerLang Class Reference

Public Member Functions

 __construct ($lang="")
 
 getLang ()
 
 loadLang ($langfile, $lang="en")
 
 get ($name, $search=[], $replace=[])
 
 __get ($name)
 

Static Public Attributes

static $languages
 
static chs
 

Constructor & Destructor Documentation

◆ __construct()

__construct (   $lang = "")

InstallerLang constructor.

Parameters
string$lang
48  {
49  if(file_exists(\pocketmine\PATH . "src/pocketmine/lang/Installer/" . $lang . ".ini")){
50  $this->lang = $lang;
51  $this->langfile = \pocketmine\PATH . "src/pocketmine/lang/Installer/" . $lang . ".ini";
52  }else{
53  $files = [];
54  foreach(new \DirectoryIterator(\pocketmine\PATH . "src/pocketmine/lang/Installer/") as $file){
55  if($file->getExtension() === "ini" and substr($file->getFilename(), 0, 2) === $lang){
56  $files[$file->getFilename()] = $file->getSize();
57  }
58  }
59 
60  if(count($files) > 0){
61  arsort($files);
62  reset($files);
63  $l = key($files);
64  $l = substr($l, 0, -4);
65  $this->lang = isset(self::$languages[$l]) ? $l : $lang;
66  $this->langfile = \pocketmine\PATH . "src/pocketmine/lang/Installer/" . $l . ".ini";
67  }else{
68  $this->lang = "en";
69  $this->langfile = \pocketmine\PATH . "src/pocketmine/lang/Installer/eng.ini";
70  }
71  }
72 
73  $this->loadLang(\pocketmine\PATH . "src/pocketmine/lang/Installer/eng.ini", "eng");
74  if($this->lang !== "en"){
75  $this->loadLang($this->langfile, $this->lang);
76  }
77 
78  }

Member Function Documentation

◆ __get()

__get (   $name)
Parameters
$name
Returns
mixed
130  {
131  return $this->get($name);
132  }

◆ get()

get (   $name,
  $search = [],
  $replace = [] 
)
Parameters
$name
array$search
array$replace
Returns
mixed
111  {
112  if(!isset($this->texts[$this->lang][$name])){
113  if($this->lang !== "en" and isset($this->texts["en"][$name])){
114  return $this->texts["en"][$name];
115  }else{
116  return $name;
117  }
118  }elseif(count($search) > 0){
119  return str_replace($search, $replace, $this->texts[$this->lang][$name]);
120  }else{
121  return $this->texts[$this->lang][$name];
122  }
123  }

◆ getLang()

getLang ( )
Returns
string
83  {
84  return ($this->lang);
85  }

◆ loadLang()

loadLang (   $langfile,
  $lang = "en" 
)
Parameters
$langfile
string$lang
91  {
92  $this->texts[$lang] = [];
93  $texts = explode("\n", str_replace(["\r", "\\/\\/"], ["", "//"], file_get_contents($langfile)));
94  foreach($texts as $line){
95  $line = trim($line);
96  if($line === ""){
97  continue;
98  }
99  $line = explode("=", $line);
100  $this->texts[$lang][trim(array_shift($line))] = trim(str_replace(["\\n", "\\N",], "\n", implode("=", $line)));
101  }
102  }

Field Documentation

◆ $languages

$languages
static
Initial value:
= [
"eng" => "English"

◆ chs

chs
static
Initial value:
=> "简体中文",
"zho" => "繁體中文",
"jpn" => "日本語",
"rus" => "Русский",
"ita" => "Italiano",
"kor" => "한국어",
"deu" => "Deutsch",
"fra" => "Français",
"ind" => "Bahasa Indonesia",
"ukr" => "Україна"
]

The documentation for this class was generated from the following file: