mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-09 11:31:49 +00:00
Support for nested TranslationContainers
This commit is contained in:
parent
804d02b086
commit
8b9d7d6390
@ -143,7 +143,7 @@ HEADER;
|
|||||||
}
|
}
|
||||||
echo "\tpublic static function " .
|
echo "\tpublic static function " .
|
||||||
functionify($key) .
|
functionify($key) .
|
||||||
"(" . implode(", ", array_map(fn(string $paramName) => "string \$$paramName", $parameters)) . ") : TranslationContainer{\n";
|
"(" . implode(", ", array_map(fn(string $paramName) => "TranslationContainer|string \$$paramName", $parameters)) . ") : TranslationContainer{\n";
|
||||||
echo "\t\treturn new TranslationContainer(KnownTranslationKeys::" . constantify($key) . ", [";
|
echo "\t\treturn new TranslationContainer(KnownTranslationKeys::" . constantify($key) . ", [";
|
||||||
foreach($parameters as $parameterKey => $parameterName){
|
foreach($parameters as $parameterKey => $parameterName){
|
||||||
echo "\n\t\t\t";
|
echo "\n\t\t\t";
|
||||||
|
@ -88,7 +88,7 @@ class VersionCommand extends VanillaCommand{
|
|||||||
}else{
|
}else{
|
||||||
$jitStatus = KnownTranslationFactory::pocketmine_command_version_phpJitNotSupported();
|
$jitStatus = KnownTranslationFactory::pocketmine_command_version_phpJitNotSupported();
|
||||||
}
|
}
|
||||||
$sender->sendMessage(KnownTranslationFactory::pocketmine_command_version_phpJitStatus($sender->getLanguage()->translate($jitStatus)));
|
$sender->sendMessage(KnownTranslationFactory::pocketmine_command_version_phpJitStatus($jitStatus));
|
||||||
$sender->sendMessage(KnownTranslationFactory::pocketmine_command_version_operatingSystem(Utils::getOS()));
|
$sender->sendMessage(KnownTranslationFactory::pocketmine_command_version_operatingSystem(Utils::getOS()));
|
||||||
}else{
|
}else{
|
||||||
$pluginName = implode(" ", $args);
|
$pluginName = implode(" ", $args);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -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{
|
public function translateString(string $str, array $params = [], ?string $onlyPrefix = null) : string{
|
||||||
$baseText = $this->get($str);
|
$baseText = $this->get($str);
|
||||||
$baseText = $this->parseTranslation(($onlyPrefix === null or strpos($str, $onlyPrefix) === 0) ? $baseText : $str, $onlyPrefix);
|
$baseText = $this->parseTranslation(($onlyPrefix === null or strpos($str, $onlyPrefix) === 0) ? $baseText : $str, $onlyPrefix);
|
||||||
|
|
||||||
foreach($params as $i => $p){
|
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;
|
return $baseText;
|
||||||
@ -148,7 +149,8 @@ class Language{
|
|||||||
$baseText = $this->parseTranslation($baseText ?? $c->getText());
|
$baseText = $this->parseTranslation($baseText ?? $c->getText());
|
||||||
|
|
||||||
foreach($c->getParameters() as $i => $p){
|
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;
|
return $baseText;
|
||||||
|
@ -27,17 +27,21 @@ final class TranslationContainer{
|
|||||||
|
|
||||||
/** @var string $text */
|
/** @var string $text */
|
||||||
protected $text;
|
protected $text;
|
||||||
/** @var string[] $params */
|
/** @var string[]|TranslationContainer[] $params */
|
||||||
protected $params = [];
|
protected $params = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param (float|int|string)[] $params
|
* @param (float|int|string|TranslationContainer)[] $params
|
||||||
*/
|
*/
|
||||||
public function __construct(string $text, array $params = []){
|
public function __construct(string $text, array $params = []){
|
||||||
$this->text = $text;
|
$this->text = $text;
|
||||||
|
|
||||||
foreach($params as $k => $str){
|
foreach($params as $k => $param){
|
||||||
$this->params[$k] = (string) $str;
|
if(!($param instanceof TranslationContainer)){
|
||||||
|
$this->params[$k] = (string) $param;
|
||||||
|
}else{
|
||||||
|
$this->params[$k] = $param;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,13 +50,13 @@ final class TranslationContainer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]|TranslationContainer[]
|
||||||
*/
|
*/
|
||||||
public function getParameters() : array{
|
public function getParameters() : array{
|
||||||
return $this->params;
|
return $this->params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getParameter(int|string $i) : ?string{
|
public function getParameter(int|string $i) : TranslationContainer|string|null{
|
||||||
return $this->params[$i] ?? null;
|
return $this->params[$i] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +113,7 @@ use pocketmine\world\sound\Sound;
|
|||||||
use pocketmine\world\World;
|
use pocketmine\world\World;
|
||||||
use Ramsey\Uuid\UuidInterface;
|
use Ramsey\Uuid\UuidInterface;
|
||||||
use function abs;
|
use function abs;
|
||||||
|
use function array_map;
|
||||||
use function assert;
|
use function assert;
|
||||||
use function count;
|
use function count;
|
||||||
use function explode;
|
use function explode;
|
||||||
@ -1781,9 +1782,11 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string[] $parameters
|
* @param string[]|TranslationContainer[] $parameters
|
||||||
*/
|
*/
|
||||||
public function sendTranslation(string $message, array $parameters = []) : void{
|
public function sendTranslation(string $message, array $parameters = []) : void{
|
||||||
|
//we can't send nested translations to the client, so make sure they are always pre-translated by the server
|
||||||
|
$parameters = array_map(fn(string|TranslationContainer $p) => $p instanceof TranslationContainer ? $this->getLanguage()->translate($p) : $p, $parameters);
|
||||||
if(!$this->server->isLanguageForced()){
|
if(!$this->server->isLanguageForced()){
|
||||||
foreach($parameters as $i => $p){
|
foreach($parameters as $i => $p){
|
||||||
$parameters[$i] = $this->getLanguage()->translateString($p, [], "pocketmine.");
|
$parameters[$i] = $this->getLanguage()->translateString($p, [], "pocketmine.");
|
||||||
|
@ -257,7 +257,7 @@ class PluginManager{
|
|||||||
|
|
||||||
$name = $description->getName();
|
$name = $description->getName();
|
||||||
if(stripos($name, "pocketmine") !== false or stripos($name, "minecraft") !== false or stripos($name, "mojang") !== false){
|
if(stripos($name, "pocketmine") !== false or stripos($name, "minecraft") !== false or stripos($name, "mojang") !== false){
|
||||||
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError($name, "%" . KnownTranslationKeys::POCKETMINE_PLUGIN_RESTRICTEDNAME)));
|
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError($name, KnownTranslationFactory::pocketmine_plugin_restrictedName())));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(strpos($name, " ") !== false){
|
if(strpos($name, " ") !== false){
|
||||||
@ -272,7 +272,7 @@ class PluginManager{
|
|||||||
if(!ApiVersion::isCompatible($this->server->getApiVersion(), $description->getCompatibleApis())){
|
if(!ApiVersion::isCompatible($this->server->getApiVersion(), $description->getCompatibleApis())){
|
||||||
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
|
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
|
||||||
$name,
|
$name,
|
||||||
$this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_incompatibleAPI(implode(", ", $description->getCompatibleApis())))
|
KnownTranslationFactory::pocketmine_plugin_incompatibleAPI(implode(", ", $description->getCompatibleApis()))
|
||||||
)));
|
)));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ class PluginManager{
|
|||||||
if(count($ambiguousVersions) > 0){
|
if(count($ambiguousVersions) > 0){
|
||||||
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
|
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
|
||||||
$name,
|
$name,
|
||||||
$this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_ambiguousMinAPI(implode(", ", $ambiguousVersions)))
|
KnownTranslationFactory::pocketmine_plugin_ambiguousMinAPI(implode(", ", $ambiguousVersions))
|
||||||
)));
|
)));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -288,7 +288,7 @@ class PluginManager{
|
|||||||
if(count($description->getCompatibleOperatingSystems()) > 0 and !in_array(Utils::getOS(), $description->getCompatibleOperatingSystems(), true)) {
|
if(count($description->getCompatibleOperatingSystems()) > 0 and !in_array(Utils::getOS(), $description->getCompatibleOperatingSystems(), true)) {
|
||||||
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
|
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
|
||||||
$name,
|
$name,
|
||||||
$this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_incompatibleOS(implode(", ", $description->getCompatibleOperatingSystems())))
|
KnownTranslationFactory::pocketmine_plugin_incompatibleOS(implode(", ", $description->getCompatibleOperatingSystems()))
|
||||||
)));
|
)));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -298,7 +298,7 @@ class PluginManager{
|
|||||||
if(count(array_intersect($pluginMcpeProtocols, $serverMcpeProtocols)) === 0){
|
if(count(array_intersect($pluginMcpeProtocols, $serverMcpeProtocols)) === 0){
|
||||||
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
|
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
|
||||||
$name,
|
$name,
|
||||||
$this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_incompatibleProtocol(implode(", ", $pluginMcpeProtocols)))
|
KnownTranslationFactory::pocketmine_plugin_incompatibleProtocol(implode(", ", $pluginMcpeProtocols))
|
||||||
)));
|
)));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -336,7 +336,7 @@ class PluginManager{
|
|||||||
}elseif(!isset($plugins[$dependency])){
|
}elseif(!isset($plugins[$dependency])){
|
||||||
$this->server->getLogger()->critical($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
|
$this->server->getLogger()->critical($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
|
||||||
$name,
|
$name,
|
||||||
$this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_unknownDependency($dependency))
|
KnownTranslationFactory::pocketmine_plugin_unknownDependency($dependency)
|
||||||
)));
|
)));
|
||||||
unset($plugins[$name]);
|
unset($plugins[$name]);
|
||||||
continue 2;
|
continue 2;
|
||||||
@ -381,7 +381,7 @@ class PluginManager{
|
|||||||
if($loadedThisLoop === 0){
|
if($loadedThisLoop === 0){
|
||||||
//No plugins loaded :(
|
//No plugins loaded :(
|
||||||
foreach($plugins as $name => $file){
|
foreach($plugins as $name => $file){
|
||||||
$this->server->getLogger()->critical($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError($name, "%" . KnownTranslationKeys::POCKETMINE_PLUGIN_CIRCULARDEPENDENCY)));
|
$this->server->getLogger()->critical($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError($name, KnownTranslationFactory::pocketmine_plugin_circularDependency())));
|
||||||
}
|
}
|
||||||
$plugins = [];
|
$plugins = [];
|
||||||
}
|
}
|
||||||
|
@ -196,9 +196,9 @@ class WorldManager{
|
|||||||
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_loadError(
|
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_loadError(
|
||||||
$name,
|
$name,
|
||||||
count($providers) === 0 ?
|
count($providers) === 0 ?
|
||||||
$this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_unknownFormat()) :
|
KnownTranslationFactory::pocketmine_level_unknownFormat() :
|
||||||
$this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_ambiguousFormat(implode(", ", array_keys($providers)))
|
KnownTranslationFactory::pocketmine_level_ambiguousFormat(implode(", ", array_keys($providers)))
|
||||||
))));
|
)));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$providerClass = array_shift($providers);
|
$providerClass = array_shift($providers);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user