59 $path = \pocketmine\LOCALE_DATA_PATH;
63 $allFiles = scandir($path, SCANDIR_SORT_NONE);
65 if($allFiles !==
false){
66 $files = array_filter($allFiles,
function(
string $filename) :
bool{
67 return str_ends_with($filename,
".ini");
72 foreach($files as $file){
74 $code = explode(
".", $file)[0];
76 if(isset($strings[KnownTranslationKeys::LANGUAGE_NAME])){
77 $result[$code] = $strings[KnownTranslationKeys::LANGUAGE_NAME];
79 }
catch(LanguageNotFoundException $e){
88 throw new LanguageNotFoundException(
"Language directory $path does not exist or is not a directory");
106 public function __construct(
string $lang, ?
string $path =
null,
string $fallback = self::FALLBACK_LANGUAGE){
107 $this->langName = strtolower($lang);
110 $path = \pocketmine\LOCALE_DATA_PATH;
113 $this->lang = self::loadLang($path, $this->langName);
114 $this->fallbackLang = self::loadLang($path, $fallback);
144 public function translateString(
string $str, array $params = [], ?
string $onlyPrefix =
null) : string{
145 $baseText = ($onlyPrefix === null || str_starts_with($str, $onlyPrefix)) ? $this->internalGet($str) : null;
146 if($baseText ===
null){
147 $baseText = $this->parseTranslation($str, $onlyPrefix);
150 foreach($params as $i => $p){
151 $replacement = $p instanceof
Translatable ? $this->translate($p) : (string) $p;
152 $baseText = str_replace(
"{%$i}", $replacement, $baseText);
204 $replaceString =
null;
206 $len = strlen($text);
207 for($i = 0; $i < $len; ++$i){
209 if($replaceString !==
null){
212 ($ord >= 0x30 && $ord <= 0x39)
213 || ($ord >= 0x41 && $ord <= 0x5a)
214 || ($ord >= 0x61 && $ord <= 0x7a) ||
215 $c ===
"." || $c ===
"-"
217 $replaceString .= $c;
219 if(($t = $this->internalGet(substr($replaceString, 1))) !==
null && ($onlyPrefix ===
null || strpos($replaceString, $onlyPrefix) === 1)){
222 $newString .= $replaceString;
224 $replaceString =
null;
239 if($replaceString !==
null){
240 if(($t = $this->internalGet(substr($replaceString, 1))) !==
null && ($onlyPrefix ===
null || strpos($replaceString, $onlyPrefix) === 1)){
243 $newString .= $replaceString;