|
1
|
|
|
<?php // Copyright ⓒ 2018 Magneds IP B.V. - All Rights Reserved |
|
2
|
|
|
namespace Magneds\Lokalise\TranslateString\Entity; |
|
3
|
|
|
|
|
4
|
|
|
use DateTime; |
|
5
|
|
|
use DateTimeZone; |
|
6
|
|
|
|
|
7
|
|
|
class TranslateString |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var string |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $key; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $translation; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string|null |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $pluralKey; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var int |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $platformMask; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var boolean |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $hidden; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $tags; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var boolean |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $fuzzy; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var string|null |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $context; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var boolean |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $archived; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var DateTime |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $modified; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var DateTime |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $created; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* TranslateString constructor. |
|
66
|
|
|
* @param string $key |
|
67
|
|
|
* @param string $translation |
|
68
|
|
|
* @param null|string $pluralKey |
|
69
|
|
|
* @param int $platformMask |
|
70
|
|
|
* @param bool $hidden |
|
71
|
|
|
* @param array $tags |
|
72
|
|
|
* @param bool $fuzzy |
|
73
|
|
|
* @param null|string $context |
|
74
|
|
|
* @param bool $archived |
|
75
|
|
|
* @param DateTime $modified |
|
76
|
|
|
* @param DateTime $created |
|
77
|
|
|
*/ |
|
78
|
|
|
public function __construct( |
|
79
|
|
|
string $key, |
|
80
|
|
|
string $translation, |
|
81
|
|
|
$pluralKey, |
|
82
|
|
|
int $platformMask, |
|
83
|
|
|
bool $hidden, |
|
84
|
|
|
array $tags, |
|
85
|
|
|
bool $fuzzy, |
|
86
|
|
|
$context, |
|
87
|
|
|
bool $archived, |
|
88
|
|
|
DateTime $modified, |
|
89
|
|
|
DateTime $created |
|
90
|
|
|
) { |
|
91
|
|
|
$this->key = $key; |
|
92
|
|
|
$this->translation = $translation; |
|
93
|
|
|
$this->pluralKey = $pluralKey; |
|
94
|
|
|
$this->platformMask = $platformMask; |
|
95
|
|
|
$this->hidden = $hidden; |
|
96
|
|
|
$this->tags = $tags; |
|
97
|
|
|
$this->fuzzy = $fuzzy; |
|
98
|
|
|
$this->context = $context; |
|
99
|
|
|
$this->archived = $archived; |
|
100
|
|
|
$this->modified = $modified; |
|
101
|
|
|
$this->created = $created; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public static function buildFromArray($array) |
|
105
|
|
|
{ |
|
106
|
|
|
$timezone = new DateTimeZone('Europe/Amsterdam'); |
|
107
|
|
|
$utc = new DateTimeZone('UTC'); |
|
108
|
|
|
|
|
109
|
|
|
$created = DateTime::createFromFormat('Y-m-d H:i:s', $array['created_at'], $timezone); |
|
110
|
|
|
$created->setTimezone($utc); |
|
111
|
|
|
|
|
112
|
|
|
$modified = DateTime::createFromFormat('Y-m-d H:i:s', $array['modified_at'], $timezone); |
|
113
|
|
|
$modified->setTimezone($utc); |
|
114
|
|
|
|
|
115
|
|
|
return new TranslateString( |
|
116
|
|
|
$array['key'], |
|
117
|
|
|
$array['translation'], |
|
118
|
|
|
$array['plural_key'], |
|
119
|
|
|
$array['platform_mask'], |
|
120
|
|
|
(bool) $array['is_hidden'], |
|
121
|
|
|
$array['tags'], |
|
122
|
|
|
(bool) $array['fuzzy'], |
|
123
|
|
|
$array['context'], |
|
124
|
|
|
(bool) $array['is_archived'], |
|
125
|
|
|
$modified, |
|
|
|
|
|
|
126
|
|
|
$created |
|
|
|
|
|
|
127
|
|
|
); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return string |
|
132
|
|
|
*/ |
|
133
|
|
|
public function getKey(): string |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->key; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @return string |
|
140
|
|
|
*/ |
|
141
|
|
|
public function getTranslation(): string |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->translation; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @return null|string |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getPluralKey(): string |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->pluralKey; |
|
|
|
|
|
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @return int |
|
156
|
|
|
*/ |
|
157
|
|
|
public function getPlatformMask(): int |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->platformMask; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @return bool |
|
164
|
|
|
*/ |
|
165
|
|
|
public function isHidden(): bool |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->hidden; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @return array |
|
172
|
|
|
*/ |
|
173
|
|
|
public function getTags(): array |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->tags; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @return bool |
|
180
|
|
|
*/ |
|
181
|
|
|
public function isFuzzy(): bool |
|
182
|
|
|
{ |
|
183
|
|
|
return $this->fuzzy; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @return null|string |
|
188
|
|
|
*/ |
|
189
|
|
|
public function getContext(): string |
|
190
|
|
|
{ |
|
191
|
|
|
return $this->context; |
|
|
|
|
|
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @return bool |
|
196
|
|
|
*/ |
|
197
|
|
|
public function isArchived(): bool |
|
198
|
|
|
{ |
|
199
|
|
|
return $this->archived; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @return DateTime |
|
204
|
|
|
*/ |
|
205
|
|
|
public function getModified(): DateTime |
|
206
|
|
|
{ |
|
207
|
|
|
return $this->modified; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @return DateTime |
|
212
|
|
|
*/ |
|
213
|
|
|
public function getCreated(): DateTime |
|
214
|
|
|
{ |
|
215
|
|
|
return $this->created; |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|