PocketMine-MP 5.19.1 git-5cc1068cd43264d3363295eb8d6901e02f467897
Translatable.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\lang;
25
26final class Translatable{
28 protected array $params = [];
29
33 public function __construct(
34 protected string $text,
35 array $params = []
36 ){
37 foreach($params as $k => $param){
38 if(!($param instanceof Translatable)){
39 $this->params[$k] = (string) $param;
40 }else{
41 $this->params[$k] = $param;
42 }
43 }
44 }
45
46 public function getText() : string{
47 return $this->text;
48 }
49
53 public function getParameters() : array{
54 return $this->params;
55 }
56
57 public function getParameter(int|string $i) : Translatable|string|null{
58 return $this->params[$i] ?? null;
59 }
60
61 public function format(string $before, string $after) : self{
62 return new self("$before%$this->text$after", $this->params);
63 }
64
65 public function prefix(string $prefix) : self{
66 return new self("$prefix%$this->text", $this->params);
67 }
68
69 public function postfix(string $postfix) : self{
70 return new self("%$this->text" . $postfix);
71 }
72}
__construct(protected string $text, array $params=[])