mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-20 15:41:33 +00:00
Support for nested TranslationContainers
This commit is contained in:
@@ -130,14 +130,15 @@ class Language{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param (float|int|string)[] $params
|
||||
* @param (float|int|string|TranslationContainer)[] $params
|
||||
*/
|
||||
public function translateString(string $str, array $params = [], ?string $onlyPrefix = null) : string{
|
||||
$baseText = $this->get($str);
|
||||
$baseText = $this->parseTranslation(($onlyPrefix === null or strpos($str, $onlyPrefix) === 0) ? $baseText : $str, $onlyPrefix);
|
||||
|
||||
foreach($params as $i => $p){
|
||||
$baseText = str_replace("{%$i}", $this->parseTranslation((string) $p), $baseText);
|
||||
$replacement = $p instanceof TranslationContainer ? $this->translate($p) : $this->parseTranslation((string) $p);
|
||||
$baseText = str_replace("{%$i}", $replacement, $baseText);
|
||||
}
|
||||
|
||||
return $baseText;
|
||||
@@ -148,7 +149,8 @@ class Language{
|
||||
$baseText = $this->parseTranslation($baseText ?? $c->getText());
|
||||
|
||||
foreach($c->getParameters() as $i => $p){
|
||||
$baseText = str_replace("{%$i}", $this->parseTranslation($p), $baseText);
|
||||
$replacement = $p instanceof TranslationContainer ? $this->translate($p) : $this->parseTranslation($p);
|
||||
$baseText = str_replace("{%$i}", $replacement, $baseText);
|
||||
}
|
||||
|
||||
return $baseText;
|
||||
|
Reference in New Issue
Block a user