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

@ -28,7 +28,7 @@ declare(strict_types=1);
namespace pocketmine\wizard;
use pocketmine\data\java\GameModeIdMap;
use pocketmine\lang\KnownTranslationKeys;
use pocketmine\lang\KnownTranslationFactory;
use pocketmine\lang\Language;
use pocketmine\lang\LanguageNotFoundException;
use pocketmine\player\GameMode;
@ -83,7 +83,7 @@ class SetupWizard{
$this->lang = new Language($lang);
$this->message($this->lang->get(KnownTranslationKeys::LANGUAGE_HAS_BEEN_SELECTED));
$this->message($this->lang->translate(KnownTranslationFactory::language_has_been_selected()));
if(!$this->showLicense()){
return false;
@ -94,7 +94,7 @@ class SetupWizard{
$config->set("language", $lang);
$config->save();
if(strtolower($this->getInput($this->lang->get(KnownTranslationKeys::SKIP_INSTALLER), "n", "y/N")) === "y"){
if(strtolower($this->getInput($this->lang->translate(KnownTranslationFactory::skip_installer()), "n", "y/N")) === "y"){
$this->printIpDetails();
return true;
}
@ -113,7 +113,7 @@ class SetupWizard{
}
private function showLicense() : bool{
$this->message($this->lang->translateString(KnownTranslationKeys::WELCOME_TO_POCKETMINE, [VersionInfo::NAME]));
$this->message($this->lang->translate(KnownTranslationFactory::welcome_to_pocketmine(VersionInfo::NAME)));
echo <<<LICENSE
This program is free software: you can redistribute it and/or modify
@ -123,8 +123,8 @@ class SetupWizard{
LICENSE;
$this->writeLine();
if(strtolower($this->getInput($this->lang->get(KnownTranslationKeys::ACCEPT_LICENSE), "n", "y/N")) !== "y"){
$this->error($this->lang->translateString(KnownTranslationKeys::YOU_HAVE_TO_ACCEPT_THE_LICENSE, [VersionInfo::NAME]));
if(strtolower($this->getInput($this->lang->translate(KnownTranslationFactory::accept_license()), "n", "y/N")) !== "y"){
$this->error($this->lang->translate(KnownTranslationFactory::you_have_to_accept_the_license(VersionInfo::NAME)));
sleep(5);
return false;
@ -134,23 +134,23 @@ LICENSE;
}
private function welcome() : void{
$this->message($this->lang->get(KnownTranslationKeys::SETTING_UP_SERVER_NOW));
$this->message($this->lang->get(KnownTranslationKeys::DEFAULT_VALUES_INFO));
$this->message($this->lang->get(KnownTranslationKeys::SERVER_PROPERTIES));
$this->message($this->lang->translate(KnownTranslationFactory::setting_up_server_now()));
$this->message($this->lang->translate(KnownTranslationFactory::default_values_info()));
$this->message($this->lang->translate(KnownTranslationFactory::server_properties()));
}
private function generateBaseConfig() : void{
$config = new Config(Path::join($this->dataPath, "server.properties"), Config::PROPERTIES);
$config->set("motd", ($name = $this->getInput($this->lang->get(KnownTranslationKeys::NAME_YOUR_SERVER), self::DEFAULT_NAME)));
$config->set("motd", ($name = $this->getInput($this->lang->translate(KnownTranslationFactory::name_your_server()), self::DEFAULT_NAME)));
$config->set("server-name", $name);
$this->message($this->lang->get(KnownTranslationKeys::PORT_WARNING));
$this->message($this->lang->translate(KnownTranslationFactory::port_warning()));
do{
$port = (int) $this->getInput($this->lang->get(KnownTranslationKeys::SERVER_PORT), (string) self::DEFAULT_PORT);
$port = (int) $this->getInput($this->lang->translate(KnownTranslationFactory::server_port()), (string) self::DEFAULT_PORT);
if($port <= 0 or $port > 65535){
$this->error($this->lang->get(KnownTranslationKeys::INVALID_PORT));
$this->error($this->lang->translate(KnownTranslationFactory::invalid_port()));
continue;
}
@ -158,35 +158,35 @@ LICENSE;
}while(true);
$config->set("server-port", $port);
$this->message($this->lang->get(KnownTranslationKeys::GAMEMODE_INFO));
$this->message($this->lang->translate(KnownTranslationFactory::gamemode_info()));
do{
$gamemode = (int) $this->getInput($this->lang->get(KnownTranslationKeys::DEFAULT_GAMEMODE), (string) GameModeIdMap::getInstance()->toId(GameMode::SURVIVAL()));
$gamemode = (int) $this->getInput($this->lang->translate(KnownTranslationFactory::default_gamemode()), (string) GameModeIdMap::getInstance()->toId(GameMode::SURVIVAL()));
}while($gamemode < 0 or $gamemode > 3);
$config->set("gamemode", $gamemode);
$config->set("max-players", (int) $this->getInput($this->lang->get(KnownTranslationKeys::MAX_PLAYERS), (string) self::DEFAULT_PLAYERS));
$config->set("max-players", (int) $this->getInput($this->lang->translate(KnownTranslationFactory::max_players()), (string) self::DEFAULT_PLAYERS));
$config->save();
}
private function generateUserFiles() : void{
$this->message($this->lang->get(KnownTranslationKeys::OP_INFO));
$this->message($this->lang->translate(KnownTranslationFactory::op_info()));
$op = strtolower($this->getInput($this->lang->get(KnownTranslationKeys::OP_WHO), ""));
$op = strtolower($this->getInput($this->lang->translate(KnownTranslationFactory::op_who()), ""));
if($op === ""){
$this->error($this->lang->get(KnownTranslationKeys::OP_WARNING));
$this->error($this->lang->translate(KnownTranslationFactory::op_warning()));
}else{
$ops = new Config(Path::join($this->dataPath, "ops.txt"), Config::ENUM);
$ops->set($op, true);
$ops->save();
}
$this->message($this->lang->get(KnownTranslationKeys::WHITELIST_INFO));
$this->message($this->lang->translate(KnownTranslationFactory::whitelist_info()));
$config = new Config(Path::join($this->dataPath, "server.properties"), Config::PROPERTIES);
if(strtolower($this->getInput($this->lang->get(KnownTranslationKeys::WHITELIST_ENABLE), "n", "y/N")) === "y"){
$this->error($this->lang->get(KnownTranslationKeys::WHITELIST_WARNING));
if(strtolower($this->getInput($this->lang->translate(KnownTranslationFactory::whitelist_enable()), "n", "y/N")) === "y"){
$this->error($this->lang->translate(KnownTranslationFactory::whitelist_warning()));
$config->set("white-list", true);
}else{
$config->set("white-list", false);
@ -196,9 +196,9 @@ LICENSE;
private function networkFunctions() : void{
$config = new Config(Path::join($this->dataPath, "server.properties"), Config::PROPERTIES);
$this->error($this->lang->get(KnownTranslationKeys::QUERY_WARNING1));
$this->error($this->lang->get(KnownTranslationKeys::QUERY_WARNING2));
if(strtolower($this->getInput($this->lang->get(KnownTranslationKeys::QUERY_DISABLE), "n", "y/N")) === "y"){
$this->error($this->lang->translate(KnownTranslationFactory::query_warning1()));
$this->error($this->lang->translate(KnownTranslationFactory::query_warning2()));
if(strtolower($this->getInput($this->lang->translate(KnownTranslationFactory::query_disable()), "n", "y/N")) === "y"){
$config->set("enable-query", false);
}else{
$config->set("enable-query", true);
@ -208,7 +208,7 @@ LICENSE;
}
private function printIpDetails() : void{
$this->message($this->lang->get(KnownTranslationKeys::IP_GET));
$this->message($this->lang->translate(KnownTranslationFactory::ip_get()));
$externalIP = Internet::getIP();
if($externalIP === false){
@ -220,15 +220,15 @@ LICENSE;
$internalIP = "unknown (" . $e->getMessage() . ")";
}
$this->error($this->lang->translateString(KnownTranslationKeys::IP_WARNING, ["EXTERNAL_IP" => $externalIP, "INTERNAL_IP" => $internalIP]));
$this->error($this->lang->get(KnownTranslationKeys::IP_CONFIRM));
$this->error($this->lang->translate(KnownTranslationFactory::ip_warning($externalIP, $internalIP)));
$this->error($this->lang->translate(KnownTranslationFactory::ip_confirm()));
$this->readLine();
}
private function endWizard() : void{
$this->message($this->lang->get(KnownTranslationKeys::YOU_HAVE_FINISHED));
$this->message($this->lang->get(KnownTranslationKeys::POCKETMINE_PLUGINS));
$this->message($this->lang->translateString(KnownTranslationKeys::POCKETMINE_WILL_START, [VersionInfo::NAME]));
$this->message($this->lang->translate(KnownTranslationFactory::you_have_finished()));
$this->message($this->lang->translate(KnownTranslationFactory::pocketmine_plugins()));
$this->message($this->lang->translate(KnownTranslationFactory::pocketmine_will_start(VersionInfo::NAME)));
$this->writeLine();
$this->writeLine();