Removed InstallerLang mess, language improvements, updated PocketMine-Language submodule

This commit is contained in:
Dylan K. Taylor
2017-02-15 14:43:38 +00:00
parent b3beb9f71d
commit 2d5567d9dd
39 changed files with 74 additions and 1081 deletions

View File

@ -1,118 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\wizard;
class InstallerLang{
public static $languages = [
"en" => "English",
"es" => "Español",
"zh" => "中文",
"ru" => "Pyccĸий",
"ja" => "日本語",
"de" => "Deutsch",
//"vi" => "Tiếng Việt",
"ko" => "한국어",
"nl" => "Nederlands",
"fr" => "Français",
"it" => "Italiano",
//"lv" => "Latviešu",
"ms" => "Melayu",
"no" => "Norsk",
//"pt" => "Português",
"sv" => "Svenska",
"fi" => "Suomi",
"tr" => "Türkçe",
//"et" => "Eesti",
];
private $texts = [];
private $lang;
private $langfile;
public function __construct($lang = ""){
if(file_exists(\pocketmine\PATH . "src/pocketmine/lang/Installer/" . $lang . ".ini")){
$this->lang = $lang;
$this->langfile = \pocketmine\PATH . "src/pocketmine/lang/Installer/" . $lang . ".ini";
}else{
$files = [];
foreach(new \DirectoryIterator(\pocketmine\PATH . "src/pocketmine/lang/Installer/") as $file){
if($file->getExtension() === "ini" and substr($file->getFilename(), 0, 2) === $lang){
$files[$file->getFilename()] = $file->getSize();
}
}
if(count($files) > 0){
arsort($files);
reset($files);
$l = key($files);
$l = substr($l, 0, -4);
$this->lang = isset(self::$languages[$l]) ? $l : $lang;
$this->langfile = \pocketmine\PATH . "src/pocketmine/lang/Installer/" . $l . ".ini";
}else{
$this->lang = "en";
$this->langfile = \pocketmine\PATH . "src/pocketmine/lang/Installer/en.ini";
}
}
$this->loadLang(\pocketmine\PATH . "src/pocketmine/lang/Installer/en.ini", "en");
if($this->lang !== "en"){
$this->loadLang($this->langfile, $this->lang);
}
}
public function getLang(){
return ($this->lang);
}
public function loadLang($langfile, $lang = "en"){
$this->texts[$lang] = [];
$texts = explode("\n", str_replace(["\r", "\\/\\/"], ["", "//"], file_get_contents($langfile)));
foreach($texts as $line){
$line = trim($line);
if($line === ""){
continue;
}
$line = explode("=", $line);
$this->texts[$lang][trim(array_shift($line))] = trim(str_replace(["\\n", "\\N",], "\n", implode("=", $line)));
}
}
public function get($name, $search = [], $replace = []){
if(!isset($this->texts[$this->lang][$name])){
if($this->lang !== "en" and isset($this->texts["en"][$name])){
return $this->texts["en"][$name];
}else{
return $name;
}
}elseif(count($search) > 0){
return str_replace($search, $replace, $this->texts[$this->lang][$name]);
}else{
return $this->texts[$this->lang][$name];
}
}
public function __get($name){
return $this->get($name);
}
}

View File

@ -25,16 +25,18 @@
*/
namespace pocketmine\wizard;
use pocketmine\lang\BaseLang;
use pocketmine\utils\Config;
use pocketmine\utils\Utils;
class Installer{
class SetupWizard{
const DEFAULT_NAME = "Minecraft: PE Server";
const DEFAULT_PORT = 19132;
const DEFAULT_MEMORY = 256;
const DEFAULT_PLAYERS = 20;
const DEFAULT_GAMEMODE = 0;
/** @var BaseLang */
private $lang;
public function __construct(){
@ -44,18 +46,20 @@ class Installer{
public function run(){
echo "[*] PocketMine-MP set-up wizard\n";
echo "[*] Please select a language:\n";
foreach(InstallerLang::$languages as $short => $native){
$langs = BaseLang::getLanguageList();
foreach($langs as $short => $native){
echo " $native => $short\n";
}
do{
echo "[?] Language (en): ";
$lang = strtolower($this->getInput("en"));
if(!isset(InstallerLang::$languages[$lang])){
echo "[?] Language (eng): ";
$lang = strtolower($this->getInput("eng"));
if(!isset($langs[$lang])){
echo "[!] Couldn't find the language\n";
$lang = false;
$lang = null;
}
}while($lang == false);
$this->lang = new InstallerLang($lang);
}while($lang === null);
$this->lang = new BaseLang($lang);
echo "[*] " . $this->lang->get("language_has_been_selected") . "\n";
@ -80,7 +84,7 @@ class Installer{
}
private function showLicense(){
echo $this->lang->welcome_to_pocketmine . "\n";
echo $this->lang->get("welcome_to_pocketmine") . "\n";
echo <<<LICENSE
This program is free software: you can redistribute it and/or modify
@ -89,9 +93,9 @@ class Installer{
(at your option) any later version.
LICENSE;
echo "\n[?] " . $this->lang->accept_license . " (y/N): ";
echo "\n[?] " . $this->lang->get("accept_license") . " (y/N): ";
if(strtolower($this->getInput("n")) != "y"){
echo "[!] " . $this->lang->you_have_to_accept_the_license . "\n";
echo "[!] " . $this->lang->get("you_have_to_accept_the_license") . "\n";
sleep(5);
return false;
@ -101,39 +105,37 @@ LICENSE;
}
private function welcome(){
echo "[*] " . $this->lang->setting_up_server_now . "\n";
echo "[*] " . $this->lang->default_values_info . "\n";
echo "[*] " . $this->lang->server_properties . "\n";
echo "[*] " . $this->lang->get("setting_up_server_now") . "\n";
echo "[*] " . $this->lang->get("default_values_info") . "\n";
echo "[*] " . $this->lang->get("server_properties") . "\n";
}
private function generateBaseConfig(){
$config = new Config(\pocketmine\DATA . "server.properties", Config::PROPERTIES);
echo "[?] " . $this->lang->name_your_server . " (" . self::DEFAULT_NAME . "): ";
echo "[?] " . $this->lang->get("name_your_server") . " (" . self::DEFAULT_NAME . "): ";
$config->set("motd", ($name = $this->getInput(self::DEFAULT_NAME)));
$config->set("server-name", $name);
echo "[*] " . $this->lang->port_warning . "\n";
echo "[*] " . $this->lang->get("port_warning") . "\n";
do{
echo "[?] " . $this->lang->server_port . " (" . self::DEFAULT_PORT . "): ";
echo "[?] " . $this->lang->get("server_port") . " (" . self::DEFAULT_PORT . "): ";
$port = (int) $this->getInput(self::DEFAULT_PORT);
if($port <= 0 or $port > 65535){
echo "[!] " . $this->lang->invalid_port . "\n";
echo "[!] " . $this->lang->get("invalid_port") . "\n";
}
}while($port <= 0 or $port > 65535);
$config->set("server-port", $port);
/*echo "[*] " . $this->lang->ram_warning . "\n";
echo "[?] " . $this->lang->server_ram . " (" . self::DEFAULT_MEMORY . "): ";
$config->set("memory-limit", ((int) $this->getInput(self::DEFAULT_MEMORY)) . "M");*/
echo "[*] " . $this->lang->gamemode_info . "\n";
echo "[*] " . $this->lang->get("gamemode_info") . "\n";
do{
echo "[?] " . $this->lang->default_gamemode . ": (" . self::DEFAULT_GAMEMODE . "): ";
echo "[?] " . $this->lang->get("default_gamemode") . ": (" . self::DEFAULT_GAMEMODE . "): ";
$gamemode = (int) $this->getInput(self::DEFAULT_GAMEMODE);
}while($gamemode < 0 or $gamemode > 3);
$config->set("gamemode", $gamemode);
echo "[?] " . $this->lang->max_players . " (" . self::DEFAULT_PLAYERS . "): ";
echo "[?] " . $this->lang->get("max_players") . " (" . self::DEFAULT_PLAYERS . "): ";
$config->set("max-players", (int) $this->getInput(self::DEFAULT_PLAYERS));
echo "[*] " . $this->lang->spawn_protection_info . "\n";
echo "[?] " . $this->lang->spawn_protection . " (Y/n): ";
echo "[*] " . $this->lang->get("spawn_protection_info") . "\n";
echo "[?] " . $this->lang->get("spawn_protection") . " (Y/n): ";
if(strtolower($this->getInput("y")) == "n"){
$config->set("spawn-protection", -1);
}else{
@ -143,21 +145,21 @@ LICENSE;
}
private function generateUserFiles(){
echo "[*] " . $this->lang->op_info . "\n";
echo "[?] " . $this->lang->op_who . ": ";
echo "[*] " . $this->lang->get("op_info") . "\n";
echo "[?] " . $this->lang->get("op_who") . ": ";
$op = strtolower($this->getInput(""));
if($op === ""){
echo "[!] " . $this->lang->op_warning . "\n";
echo "[!] " . $this->lang->get("op_warning") . "\n";
}else{
$ops = new Config(\pocketmine\DATA . "ops.txt", Config::ENUM);
$ops->set($op, true);
$ops->save();
}
echo "[*] " . $this->lang->whitelist_info . "\n";
echo "[?] " . $this->lang->whitelist_enable . " (y/N): ";
echo "[*] " . $this->lang->get("whitelist_info") . "\n";
echo "[?] " . $this->lang->get("whitelist_enable") . " (y/N): ";
$config = new Config(\pocketmine\DATA . "server.properties", Config::PROPERTIES);
if(strtolower($this->getInput("n")) === "y"){
echo "[!] " . $this->lang->whitelist_warning . "\n";
echo "[!] " . $this->lang->get("whitelist_warning") . "\n";
$config->set("white-list", true);
}else{
$config->set("white-list", false);
@ -167,22 +169,22 @@ LICENSE;
private function networkFunctions(){
$config = new Config(\pocketmine\DATA . "server.properties", Config::PROPERTIES);
echo "[!] " . $this->lang->query_warning1 . "\n";
echo "[!] " . $this->lang->query_warning2 . "\n";
echo "[?] " . $this->lang->query_disable . " (y/N): ";
echo "[!] " . $this->lang->get("query_warning1") . "\n";
echo "[!] " . $this->lang->get("query_warning2") . "\n";
echo "[?] " . $this->lang->get("query_disable") . " (y/N): ";
if(strtolower($this->getInput("n")) === "y"){
$config->set("enable-query", false);
}else{
$config->set("enable-query", true);
}
echo "[*] " . $this->lang->rcon_info . "\n";
echo "[?] " . $this->lang->rcon_enable . " (y/N): ";
echo "[*] " . $this->lang->get("rcon_info") . "\n";
echo "[?] " . $this->lang->get("rcon_enable") . " (y/N): ";
if(strtolower($this->getInput("n")) === "y"){
$config->set("enable-rcon", true);
$password = substr(base64_encode(random_bytes(20)), 3, 10);
$config->set("rcon.password", $password);
echo "[*] " . $this->lang->rcon_password . ": " . $password . "\n";
echo "[*] " . $this->lang->get("rcon_password") . ": " . $password . "\n";
}else{
$config->set("enable-rcon", false);
}
@ -197,20 +199,20 @@ LICENSE;
$config->save();
echo "[*] " . $this->lang->ip_get . "\n";
echo "[*] " . $this->lang->get("ip_get") . "\n";
$externalIP = Utils::getIP();
$internalIP = gethostbyname(trim(`hostname`));
echo "[!] " . $this->lang->get("ip_warning", ["{{EXTERNAL_IP}}", "{{INTERNAL_IP}}"], [$externalIP, $internalIP]) . "\n";
echo "[!] " . $this->lang->ip_confirm;
echo "[!] " . $this->lang->translateString("ip_warning", ["EXTERNAL_IP" => $externalIP, "INTERNAL_IP" => $internalIP]) . "\n";
echo "[!] " . $this->lang->get("ip_confirm");
$this->getInput();
}
private function endWizard(){
echo "[*] " . $this->lang->you_have_finished . "\n";
echo "[*] " . $this->lang->pocketmine_plugins . "\n";
echo "[*] " . $this->lang->pocketmine_will_start . "\n\n\n";
echo "[*] " . $this->lang->get("you_have_finished") . "\n";
echo "[*] " . $this->lang->get("pocketmine_plugins") . "\n";
echo "[*] " . $this->lang->get("pocketmine_will_start") . "\n\n\n";
sleep(4);
}