mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 19:02:59 +00:00
Rename TranslationContainer -> Translatable
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user