Added KnownTranslationFactory and use it in as many places as possible

this makes translation usage much more statically analysable.
The only places this isn't used are:
- places that prefix translations with colours (those are still a problem)
- places where server/client translations don't match (e.g. gameMode.changed accepts different parameters in vanilla than in PM)
This commit is contained in:
Dylan K. Taylor
2021-08-10 14:50:40 +01:00
parent d39080c45a
commit 2293bd948d
52 changed files with 2185 additions and 372 deletions

View File

@@ -27,7 +27,7 @@ use pocketmine\entity\Entity;
use pocketmine\event\world\WorldInitEvent;
use pocketmine\event\world\WorldLoadEvent;
use pocketmine\event\world\WorldUnloadEvent;
use pocketmine\lang\KnownTranslationKeys;
use pocketmine\lang\KnownTranslationFactory;
use pocketmine\player\ChunkSelector;
use pocketmine\Server;
use pocketmine\timings\Timings;
@@ -149,7 +149,7 @@ class WorldManager{
return false;
}
$this->server->getLogger()->info($this->server->getLanguage()->translateString(KnownTranslationKeys::POCKETMINE_LEVEL_UNLOADING, [$world->getDisplayName()]));
$this->server->getLogger()->info($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_unloading($world->getDisplayName())));
try{
$safeSpawn = $this->defaultWorld !== null ? $this->defaultWorld->getSafeSpawn() : null;
}catch(WorldException $e){
@@ -193,12 +193,12 @@ class WorldManager{
$providers = $this->providerManager->getMatchingProviders($path);
if(count($providers) !== 1){
$this->server->getLogger()->error($this->server->getLanguage()->translateString(KnownTranslationKeys::POCKETMINE_LEVEL_LOADERROR, [
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_loadError(
$name,
count($providers) === 0 ?
$this->server->getLanguage()->translateString(KnownTranslationKeys::POCKETMINE_LEVEL_UNKNOWNFORMAT) :
$this->server->getLanguage()->translateString(KnownTranslationKeys::POCKETMINE_LEVEL_AMBIGUOUSFORMAT, [implode(", ", array_keys($providers))])
]));
$this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_unknownFormat()) :
$this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_ambiguousFormat(implode(", ", array_keys($providers)))
))));
return false;
}
$providerClass = array_shift($providers);
@@ -206,16 +206,16 @@ class WorldManager{
try{
$provider = $providerClass->fromPath($path);
}catch(CorruptedWorldException $e){
$this->server->getLogger()->error($this->server->getLanguage()->translateString(KnownTranslationKeys::POCKETMINE_LEVEL_LOADERROR, [$name, "Corruption detected: " . $e->getMessage()]));
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_loadError($name, "Corruption detected: " . $e->getMessage())));
return false;
}catch(UnsupportedWorldFormatException $e){
$this->server->getLogger()->error($this->server->getLanguage()->translateString(KnownTranslationKeys::POCKETMINE_LEVEL_LOADERROR, [$name, "Unsupported format: " . $e->getMessage()]));
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_loadError($name, "Unsupported format: " . $e->getMessage())));
return false;
}
try{
GeneratorManager::getInstance()->getGenerator($provider->getWorldData()->getGenerator(), true);
}catch(\InvalidArgumentException $e){
$this->server->getLogger()->error($this->server->getLanguage()->translateString(KnownTranslationKeys::POCKETMINE_LEVEL_LOADERROR, [$name, "Unknown generator \"" . $provider->getWorldData()->getGenerator() . "\""]));
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_loadError($name, "Unknown generator \"" . $provider->getWorldData()->getGenerator() . "\"")));
return false;
}
if(!($provider instanceof WritableWorldProvider)){
@@ -265,7 +265,7 @@ class WorldManager{
(new WorldLoadEvent($world))->call();
if($backgroundGeneration){
$this->server->getLogger()->notice($this->server->getLanguage()->translateString(KnownTranslationKeys::POCKETMINE_LEVEL_BACKGROUNDGENERATION, [$name]));
$this->server->getLogger()->notice($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_backgroundGeneration($name)));
$spawnLocation = $world->getSpawnLocation();
$centerX = $spawnLocation->getFloorX() >> 4;