◆ __construct()
__construct |
( |
|
$lang, |
|
|
|
$path = null , |
|
|
|
$fallback = self::FALLBACK_LANGUAGE |
|
) |
| |
BaseLang constructor.
- Parameters
-
| $lang | |
null | $path | |
string | $fallback | |
45 $this->langName = strtolower(
$lang);
48 $path = \pocketmine\PATH .
"src/pocketmine/lang/locale/";
51 $this->
loadLang($path . $this->langName .
".ini", $this->lang);
52 $this->
loadLang($path . $fallback .
".ini", $this->fallbackLang);
◆ get()
- Parameters
-
- Returns
- mixed
157 if(isset($this->lang[$id])){
158 return $this->lang[$id];
159 }elseif(isset($this->fallbackLang[$id])){
160 return $this->fallbackLang[$id];
◆ getLang()
◆ getName()
- Returns
- string
59 return $this->
get(
"language.name");
◆ internalGet()
- Parameters
-
- Returns
- mixed|null
142 if(isset($this->lang[$id])){
143 return $this->lang[$id];
144 }elseif(isset($this->fallbackLang[$id])){
145 return $this->fallbackLang[$id];
◆ loadLang()
loadLang |
( |
|
$path, |
|
|
array & |
$d |
|
) |
| |
|
protected |
- Parameters
-
74 if(file_exists($path) and strlen($content = file_get_contents($path)) > 0){
75 foreach(explode(
"\n", $content) as $line){
77 if($line ===
"" or $line{0} ===
"#"){
81 $t = explode(
"=", $line);
86 $key = trim(array_shift($t));
87 $value = trim(implode(
"=", $t));
◆ parseTranslation()
parseTranslation |
( |
|
$text, |
|
|
|
$onlyPrefix = null |
|
) |
| |
|
protected |
- Parameters
-
- Returns
- string
175 $replaceString = null;
177 $len = strlen($text);
178 for($i = 0; $i < $len; ++$i){
180 if($replaceString !== null){
183 ($ord >= 0x30 and $ord <= 0x39)
184 or ($ord >= 0x41 and $ord <= 0x5a)
185 or ($ord >= 0x61 and $ord <= 0x7a) or
186 $c ===
"." or $c ===
"-" 188 $replaceString .= $c;
190 if(($t = $this->
internalGet(substr($replaceString, 1))) !== null and ($onlyPrefix === null or strpos($replaceString, $onlyPrefix) === 1)){
193 $newString .= $replaceString;
195 $replaceString = null;
210 if($replaceString !== null){
211 if(($t = $this->
internalGet(substr($replaceString, 1))) !== null and ($onlyPrefix === null or strpos($replaceString, $onlyPrefix) === 1)){
214 $newString .= $replaceString;
◆ translate()
- Parameters
-
- Returns
- mixed|null|string
122 if($c instanceof TranslationContainer){
124 $baseText = $this->
parseTranslation($baseText !== null ? $baseText : $c->getText());
126 foreach($c->getParameters() as $i => $p){
◆ translateString()
translateString |
( |
|
$str, |
|
|
array |
$params = [] , |
|
|
|
$onlyPrefix = null |
|
) |
| |
- Parameters
-
string | $str | |
| string[] | $params |
string | null | $onlyPrefix | |
- Returns
- string
106 $baseText = $this->
get($str);
107 $baseText = $this->
parseTranslation(($baseText !== null and ($onlyPrefix === null or strpos($str, $onlyPrefix) === 0)) ? $baseText : $str, $onlyPrefix);
109 foreach($params as $i => $p){
110 $baseText = str_replace(
"{%$i}", $this->
parseTranslation((
string) $p), $baseText, $onlyPrefix);
113 return str_replace(
"%0",
"", $baseText);
◆ $fallbackLang
◆ $lang
◆ $langName
◆ FALLBACK_LANGUAGE
const FALLBACK_LANGUAGE = "eng" |
The documentation for this class was generated from the following file:
- src/pocketmine/lang/BaseLang.php