Rename TranslationContainer -> Translatable

This commit is contained in:
Dylan K. Taylor
2021-08-15 16:17:46 +01:00
parent 5bdcc0339f
commit 789a669395
16 changed files with 757 additions and 757 deletions

File diff suppressed because it is too large Load Diff

View File

@ -130,26 +130,26 @@ class Language{
}
/**
* @param (float|int|string|TranslationContainer)[] $params
* @param (float|int|string|Translatable)[] $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){
$replacement = $p instanceof TranslationContainer ? $this->translate($p) : $this->parseTranslation((string) $p);
$replacement = $p instanceof Translatable ? $this->translate($p) : $this->parseTranslation((string) $p);
$baseText = str_replace("{%$i}", $replacement, $baseText);
}
return $baseText;
}
public function translate(TranslationContainer $c) : string{
public function translate(Translatable $c) : string{
$baseText = $this->internalGet($c->getText());
$baseText = $this->parseTranslation($baseText ?? $c->getText());
foreach($c->getParameters() as $i => $p){
$replacement = $p instanceof TranslationContainer ? $this->translate($p) : $this->parseTranslation($p);
$replacement = $p instanceof Translatable ? $this->translate($p) : $this->parseTranslation($p);
$baseText = str_replace("{%$i}", $replacement, $baseText);
}

View File

@ -23,21 +23,21 @@ declare(strict_types=1);
namespace pocketmine\lang;
final class TranslationContainer{
final class Translatable{
/** @var string $text */
protected $text;
/** @var string[]|TranslationContainer[] $params */
/** @var string[]|Translatable[] $params */
protected $params = [];
/**
* @param (float|int|string|TranslationContainer)[] $params
* @param (float|int|string|Translatable)[] $params
*/
public function __construct(string $text, array $params = []){
$this->text = $text;
foreach($params as $k => $param){
if(!($param instanceof TranslationContainer)){
if(!($param instanceof Translatable)){
$this->params[$k] = (string) $param;
}else{
$this->params[$k] = $param;
@ -50,13 +50,13 @@ final class TranslationContainer{
}
/**
* @return string[]|TranslationContainer[]
* @return string[]|Translatable[]
*/
public function getParameters() : array{
return $this->params;
}
public function getParameter(int|string $i) : TranslationContainer|string|null{
public function getParameter(int|string $i) : Translatable|string|null{
return $this->params[$i] ?? null;
}