mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 10:49:10 +00:00
Added settings.force-language property to force server language on clients
This commit is contained in:
parent
31387ff0be
commit
1865622b89
@ -2440,11 +2440,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
*/
|
*/
|
||||||
public function sendMessage($message){
|
public function sendMessage($message){
|
||||||
if($message instanceof TextContainer){
|
if($message instanceof TextContainer){
|
||||||
if($message instanceof TranslationContainer){
|
if ($message instanceof TranslationContainer) {
|
||||||
$this->sendTranslation($message->getText(), $message->getParameters());
|
$this->sendTranslation($message->getText(), $message->getParameters());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$message = $message->getText();
|
$message = $message->getText();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$mes = explode("\n", $this->server->getLanguage()->translateString($message));
|
$mes = explode("\n", $this->server->getLanguage()->translateString($message));
|
||||||
@ -2460,12 +2461,17 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
|
|
||||||
public function sendTranslation($message, array $parameters = []){
|
public function sendTranslation($message, array $parameters = []){
|
||||||
$pk = new TextPacket();
|
$pk = new TextPacket();
|
||||||
$pk->type = TextPacket::TYPE_TRANSLATION;
|
if(!$this->server->isLanguageForced()){
|
||||||
$pk->message = $this->server->getLanguage()->translateString($message, [], "pocketmine.");
|
$pk->type = TextPacket::TYPE_TRANSLATION;
|
||||||
foreach($parameters as $i => $p){
|
$pk->message = $this->server->getLanguage()->translateString($message, [], "pocketmine.");
|
||||||
$parameters[$i] = $this->server->getLanguage()->translateString($p, [], "pocketmine.");
|
foreach($parameters as $i => $p){
|
||||||
|
$parameters[$i] = $this->server->getLanguage()->translateString($p, [], "pocketmine.");
|
||||||
|
}
|
||||||
|
$pk->parameters = $parameters;
|
||||||
|
}else{
|
||||||
|
$pk->type = TextPacket::TYPE_RAW;
|
||||||
|
$pk->message = $this->server->getLanguage()->translateString($message, $parameters);
|
||||||
}
|
}
|
||||||
$pk->parameters = $parameters;
|
|
||||||
$this->dataPacket($pk);
|
$this->dataPacket($pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,6 +201,8 @@ class Server{
|
|||||||
/** @var BaseLang */
|
/** @var BaseLang */
|
||||||
private $baseLang;
|
private $baseLang;
|
||||||
|
|
||||||
|
private $forceLanguage = false;
|
||||||
|
|
||||||
private $serverID;
|
private $serverID;
|
||||||
|
|
||||||
private $autoloader;
|
private $autoloader;
|
||||||
@ -1515,6 +1517,7 @@ class Server{
|
|||||||
"auto-save" => true,
|
"auto-save" => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->forceLanguage = $this->getProperty("settings.force-language", false);
|
||||||
$this->baseLang = new BaseLang($this->getProperty("settings.language", BaseLang::FALLBACK_LANGUAGE));
|
$this->baseLang = new BaseLang($this->getProperty("settings.language", BaseLang::FALLBACK_LANGUAGE));
|
||||||
$this->logger->info($this->getLanguage()->translateString("language.selected", [$this->getLanguage()->getName(), $this->getLanguage()->getLang()]));
|
$this->logger->info($this->getLanguage()->translateString("language.selected", [$this->getLanguage()->getName(), $this->getLanguage()->getLang()]));
|
||||||
|
|
||||||
@ -2262,6 +2265,13 @@ class Server{
|
|||||||
return $this->baseLang;
|
return $this->baseLang;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isLanguageForced(){
|
||||||
|
return $this->forceLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Network
|
* @return Network
|
||||||
*/
|
*/
|
||||||
|
@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
namespace pocketmine\event;
|
namespace pocketmine\event;
|
||||||
|
|
||||||
use pocketmine\Player;
|
|
||||||
|
|
||||||
class TextContainer{
|
class TextContainer{
|
||||||
|
|
||||||
/** @var string $text */
|
/** @var string $text */
|
||||||
@ -43,10 +41,6 @@ class TextContainer{
|
|||||||
return $this->text;
|
return $this->text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function send(Player $p){
|
|
||||||
$p->sendMessage($this->getText());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
namespace pocketmine\event;
|
namespace pocketmine\event;
|
||||||
|
|
||||||
use pocketmine\Player;
|
|
||||||
|
|
||||||
class TranslationContainer extends TextContainer{
|
class TranslationContainer extends TextContainer{
|
||||||
|
|
||||||
/** @var string[] $params */
|
/** @var string[] $params */
|
||||||
@ -77,8 +75,4 @@ class TranslationContainer extends TextContainer{
|
|||||||
++$i;
|
++$i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function send(Player $p){
|
|
||||||
$p->sendTranslation($this->getText(), $this->getParameters());
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -7,6 +7,8 @@ settings:
|
|||||||
#Three-letter language code for server-side localization
|
#Three-letter language code for server-side localization
|
||||||
#Check your language code on https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
|
#Check your language code on https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
|
||||||
language: "eng"
|
language: "eng"
|
||||||
|
#Whether to send all strings translated to server locale or let the device handle them
|
||||||
|
force-language: false
|
||||||
shutdown-message: "Server closed"
|
shutdown-message: "Server closed"
|
||||||
#Allow listing plugins via Query
|
#Allow listing plugins via Query
|
||||||
query-plugins: true
|
query-plugins: true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user