mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
Merge branch 'next-minor' into next-major
This commit is contained in:
@ -1176,6 +1176,10 @@ final class KnownTranslationFactory{
|
||||
return new Translatable(KnownTranslationKeys::POCKETMINE_COMMAND_DIFFICULTY_DESCRIPTION, []);
|
||||
}
|
||||
|
||||
public static function pocketmine_command_dumpmemory_description() : Translatable{
|
||||
return new Translatable(KnownTranslationKeys::POCKETMINE_COMMAND_DUMPMEMORY_DESCRIPTION, []);
|
||||
}
|
||||
|
||||
public static function pocketmine_command_effect_description() : Translatable{
|
||||
return new Translatable(KnownTranslationKeys::POCKETMINE_COMMAND_EFFECT_DESCRIPTION, []);
|
||||
}
|
||||
|
@ -260,6 +260,7 @@ final class KnownTranslationKeys{
|
||||
public const POCKETMINE_COMMAND_DEFAULTGAMEMODE_DESCRIPTION = "pocketmine.command.defaultgamemode.description";
|
||||
public const POCKETMINE_COMMAND_DEOP_DESCRIPTION = "pocketmine.command.deop.description";
|
||||
public const POCKETMINE_COMMAND_DIFFICULTY_DESCRIPTION = "pocketmine.command.difficulty.description";
|
||||
public const POCKETMINE_COMMAND_DUMPMEMORY_DESCRIPTION = "pocketmine.command.dumpmemory.description";
|
||||
public const POCKETMINE_COMMAND_EFFECT_DESCRIPTION = "pocketmine.command.effect.description";
|
||||
public const POCKETMINE_COMMAND_ENCHANT_DESCRIPTION = "pocketmine.command.enchant.description";
|
||||
public const POCKETMINE_COMMAND_ERROR_PERMISSION = "pocketmine.command.error.permission";
|
||||
|
@ -142,8 +142,10 @@ class Language{
|
||||
* @param (float|int|string|Translatable)[] $params
|
||||
*/
|
||||
public function translateString(string $str, array $params = [], ?string $onlyPrefix = null) : string{
|
||||
$baseText = $this->get($str);
|
||||
$baseText = $this->parseTranslation(($onlyPrefix === null || str_starts_with($str, $onlyPrefix)) ? $baseText : $str, $onlyPrefix);
|
||||
$baseText = ($onlyPrefix === null || str_starts_with($str, $onlyPrefix)) ? $this->internalGet($str) : null;
|
||||
if($baseText === null){ //key not found, embedded inside format string, or doesn't match prefix
|
||||
$baseText = $this->parseTranslation($str, $onlyPrefix);
|
||||
}
|
||||
|
||||
foreach($params as $i => $p){
|
||||
$replacement = $p instanceof Translatable ? $this->translate($p) : (string) $p;
|
||||
@ -155,7 +157,9 @@ class Language{
|
||||
|
||||
public function translate(Translatable $c) : string{
|
||||
$baseText = $this->internalGet($c->getText());
|
||||
$baseText = $this->parseTranslation($baseText ?? $c->getText());
|
||||
if($baseText === null){ //key not found or embedded inside format string
|
||||
$baseText = $this->parseTranslation($c->getText());
|
||||
}
|
||||
|
||||
foreach($c->getParameters() as $i => $p){
|
||||
$replacement = $p instanceof Translatable ? $this->translate($p) : $p;
|
||||
@ -181,6 +185,19 @@ class Language{
|
||||
return $this->lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces translation keys embedded inside a string with their raw values.
|
||||
* Embedded translation keys must be prefixed by a "%" character.
|
||||
*
|
||||
* This is used to allow the "text" field of a Translatable to contain formatting (e.g. colour codes) and
|
||||
* multiple embedded translation keys.
|
||||
*
|
||||
* Normal translations whose "text" is just a single translation key don't need to use this method, and can be
|
||||
* processed via get() directly.
|
||||
*
|
||||
* @param string|null $onlyPrefix If non-null, only translation keys with this prefix will be replaced. This is
|
||||
* used to allow a client to do its own translating of vanilla strings.
|
||||
*/
|
||||
protected function parseTranslation(string $text, ?string $onlyPrefix = null) : string{
|
||||
$newString = "";
|
||||
|
||||
|
Reference in New Issue
Block a user