1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* This file is part of the Aura Project for PHP. |
5
|
|
|
* |
6
|
|
|
* @package aura/intl |
7
|
|
|
* |
8
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
namespace Aura\Intl; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* |
15
|
|
|
* Message Catalog |
16
|
|
|
* |
17
|
|
|
* @package aura/intl |
18
|
|
|
* |
19
|
|
|
*/ |
20
|
|
|
class Package |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* |
24
|
|
|
* Message keys and translations in this package. |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
* |
28
|
|
|
*/ |
29
|
|
|
protected $messages; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* |
33
|
|
|
* The name of a fallback package to use when a message key does not |
34
|
|
|
* exist. |
35
|
|
|
* |
36
|
|
|
* @var string |
37
|
|
|
* |
38
|
|
|
*/ |
39
|
|
|
protected $fallback; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* |
43
|
|
|
* The name of the formatter to use when formatting translated messages. |
44
|
|
|
* |
45
|
|
|
* @var string |
46
|
|
|
* |
47
|
|
|
*/ |
48
|
|
|
protected $formatter; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* |
52
|
|
|
* Constructor. |
53
|
|
|
* |
54
|
|
|
* @param string $formatter The name of the formatter to use. |
55
|
|
|
* |
56
|
|
|
* @param string $fallback The name of the fallback package to use. |
57
|
|
|
* |
58
|
|
|
* @param array $messages The messages in this package. |
59
|
|
|
* |
60
|
|
|
*/ |
61
|
8 |
|
public function __construct( |
62
|
|
|
$formatter = 'basic', |
63
|
|
|
$fallback = null, |
64
|
|
|
array $messages = [] |
65
|
|
|
) { |
66
|
8 |
|
$this->formatter = $formatter; |
67
|
8 |
|
$this->fallback = $fallback; |
68
|
8 |
|
$this->messages = $messages; |
69
|
8 |
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* |
73
|
|
|
* Sets the messages for this package. |
74
|
|
|
* |
75
|
|
|
* @param array $messages The messages for this package. |
76
|
|
|
* |
77
|
|
|
* @return void |
78
|
|
|
* |
79
|
|
|
*/ |
80
|
6 |
|
public function setMessages(array $messages) |
81
|
|
|
{ |
82
|
6 |
|
$this->messages = $messages; |
83
|
6 |
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* |
87
|
|
|
* Adds one message for this package. |
88
|
|
|
* |
89
|
|
|
* @param string $key the key of the message |
90
|
|
|
* |
91
|
|
|
* @param string $message the actual message |
92
|
|
|
* |
93
|
|
|
* @return void |
94
|
|
|
* |
95
|
|
|
*/ |
96
|
1 |
|
public function addMessage($key, $message) |
97
|
|
|
{ |
98
|
1 |
|
$this->messages[$key] = $message; |
99
|
1 |
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* |
103
|
|
|
* Adds new messages for this package. |
104
|
|
|
* |
105
|
|
|
* @param array $messages The messages to add in this package. |
106
|
|
|
* |
107
|
|
|
* @return void |
108
|
|
|
* |
109
|
|
|
*/ |
110
|
|
|
public function addMessages($messages) |
111
|
|
|
{ |
112
|
|
|
$this->messages = array_merge($this->messages, $messages); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* |
117
|
|
|
* Gets the messages for this package. |
118
|
|
|
* |
119
|
|
|
* @return array |
120
|
|
|
* |
121
|
|
|
*/ |
122
|
1 |
|
public function getMessages() |
123
|
|
|
{ |
124
|
1 |
|
return $this->messages; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* |
130
|
|
|
* Gets the message of the given key for this package. |
131
|
|
|
* |
132
|
|
|
* @param string $key the key of the message to return |
133
|
|
|
* |
134
|
|
|
* @return mixed The message translation string, or false if not found. |
135
|
|
|
* |
136
|
|
|
*/ |
137
|
4 |
|
public function getMessage($key) |
138
|
|
|
{ |
139
|
4 |
|
if (isset($this->messages[$key])) { |
140
|
3 |
|
return $this->messages[$key]; |
141
|
|
|
} |
142
|
|
|
|
143
|
3 |
|
return false; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* |
148
|
|
|
* Sets the formatter name for this package. |
149
|
|
|
* |
150
|
|
|
* @param string $formatter The formatter name for this package. |
151
|
|
|
* |
152
|
|
|
* @return void |
153
|
|
|
* |
154
|
|
|
*/ |
155
|
1 |
|
public function setFormatter($formatter) |
156
|
|
|
{ |
157
|
1 |
|
$this->formatter = $formatter; |
158
|
1 |
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* |
162
|
|
|
* Gets the formatter name for this package. |
163
|
|
|
* |
164
|
|
|
* @return string |
165
|
|
|
* |
166
|
|
|
*/ |
167
|
3 |
|
public function getFormatter() |
168
|
|
|
{ |
169
|
3 |
|
return $this->formatter; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* |
174
|
|
|
* Sets the fallback package name. |
175
|
|
|
* |
176
|
|
|
* @param string $fallback The fallback package name. |
177
|
|
|
* |
178
|
|
|
* @return void |
179
|
|
|
* |
180
|
|
|
*/ |
181
|
1 |
|
public function setFallback($fallback) |
182
|
|
|
{ |
183
|
1 |
|
$this->fallback = $fallback; |
184
|
1 |
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* |
188
|
|
|
* Gets the fallback package name. |
189
|
|
|
* |
190
|
|
|
* @return string |
191
|
|
|
* |
192
|
|
|
*/ |
193
|
3 |
|
public function getFallback() |
194
|
|
|
{ |
195
|
3 |
|
return $this->fallback; |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|