-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LitCommon.php
297 lines (280 loc) · 15.4 KB
/
LitCommon.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php
include_once("includes/pgettext.php");
include_once("includes/enums/LitLocale.php");
class LitCommon
{
public const PROPRIO = "Proper";
public const DEDICATIONIS_ECCLESIAE = "Dedication of a Church";
public const BEATAE_MARIAE_VIRGINIS = "Blessed Virgin Mary";
public const MARTYRUM = "Martyrs";
public const PASTORUM = "Pastors";
public const DOCTORUM = "Doctors";
public const VIRGINUM = "Virgins";
public const SANCTORUM_ET_SANCTARUM = "Holy Men and Women";
/** MARTYRUM */
public const PRO_UNO_MARTYRE = "For One Martyr";
public const PRO_PLURIBUS_MARTYRIBUS = "For Several Martyrs";
public const PRO_MISSIONARIIS_MARTYRIBUS = "For Missionary Martyrs";
public const PRO_UNO_MISSIONARIO_MARTYRE = "For One Missionary Martyr";
public const PRO_PLURIBUS_MISSIONARIIS_MARTYRIBUS = "For Several Missionary Martyrs";
public const PRO_VIRGINE_MARTYRE = "For a Virgin Martyr";
public const PRO_SANCTA_MULIERE_MARTYRE = "For a Holy Woman Martyr";
/** PASTORUM */
public const PRO_PAPA = "For a Pope";
public const PRO_EPISCOPO = "For a Bishop";
public const PRO_UNO_PASTORE = "For One Pastor";
public const PRO_PLURIBUS_PASTORIBUS = "For Several Pastors";
public const PRO_FUNDATORIBUS_ECCLESIARUM = "For Founders of a Church";
public const PRO_UNO_FUNDATORE = "For One Founder";
public const PRO_PLURIBUS_FUNDATORIBUS = "For Several Founders";
public const PRO_MISSIONARIIS = "For Missionaries";
/** VIRGINUM */
public const PRO_UNA_VIRGINE = "For One Virgin";
public const PRO_PLURIBUS_VIRGINIBUS = "For Several Virgins";
/** SANCTORUM_ET_SANCTARUM */
public const PRO_PLURIBUS_SANCTIS = "For Several Saints";
public const PRO_UNO_SANCTO = "For One Saint";
public const PRO_ABBATE = "For an Abbot";
public const PRO_MONACHO = "For a Monk";
public const PRO_MONIALI = "For a Nun";
public const PRO_RELIGIOSIS = "For Religious";
public const PRO_IIS_QUI_OPERA_MISERICORDIAE_EXERCUERUNT = "For Those Who Practiced Works of Mercy";
public const PRO_EDUCATORIBUS = "For Educators";
public const PRO_SANCTIS_MULIERIBUS = "For Holy Women";
private string $locale;
private array $GTXT;
public function __construct(string $locale)
{
$this->locale = strtoupper($locale);
$this->GTXT = [
self::PROPRIO => _("Proper"),
/**translators: context = from the Common of nn */
self::DEDICATIONIS_ECCLESIAE => _("Dedication of a Church"),
/**translators: context = from the Common of nn */
self::BEATAE_MARIAE_VIRGINIS => _("Blessed Virgin Mary"),
/**translators: context = from the Common of nn */
self::MARTYRUM => _("Martyrs"),
/**translators: context = from the Common of nn */
self::PASTORUM => _("Pastors"),
/**translators: context = from the Common of nn */
self::DOCTORUM => _("Doctors"),
/**translators: context = from the Common of nn */
self::VIRGINUM => _("Virgins"),
/**translators: context = from the Common of nn */
self::SANCTORUM_ET_SANCTARUM => _("Holy Men and Women"),
/**translators: context = from the Common of nn: nn */
self::PRO_UNO_MARTYRE => _("For One Martyr"),
/**translators: context = from the Common of nn: nn */
self::PRO_PLURIBUS_MARTYRIBUS => _("For Several Martyrs"),
/**translators: context = from the Common of nn: nn */
self::PRO_MISSIONARIIS_MARTYRIBUS => _("For Missionary Martyrs"),
/**translators: context = from the Common of nn: nn */
self::PRO_UNO_MISSIONARIO_MARTYRE => _("For One Missionary Martyr"),
/**translators: context = from the Common of nn: nn */
self::PRO_PLURIBUS_MISSIONARIIS_MARTYRIBUS => _("For Several Missionary Martyrs"),
/**translators: context = from the Common of nn: nn */
self::PRO_VIRGINE_MARTYRE => _("For a Virgin Martyr"),
/**translators: context = from the Common of nn: nn */
self::PRO_SANCTA_MULIERE_MARTYRE => _("For a Holy Woman Martyr"),
/**translators: context = from the Common of nn: nn */
self::PRO_PAPA => _("For a Pope"),
/**translators: context = from the Common of nn: nn */
self::PRO_EPISCOPO => _("For a Bishop"),
/**translators: context = from the Common of nn: nn */
self::PRO_UNO_PASTORE => _("For One Pastor"),
/**translators: context = from the Common of nn: nn */
self::PRO_PLURIBUS_PASTORIBUS => _("For Several Pastors"),
/**translators: context = from the Common of nn: nn */
self::PRO_FUNDATORIBUS_ECCLESIARUM => _("For Founders of a Church"),
/**translators: context = from the Common of nn: nn */
self::PRO_UNO_FUNDATORE => _("For One Founder"),
/**translators: context = from the Common of nn: nn */
self::PRO_PLURIBUS_FUNDATORIBUS => _("For Several Founders"),
/**translators: context = from the Common of nn: nn */
self::PRO_MISSIONARIIS => _("For Missionaries"),
/**translators: context = from the Common of nn: nn */
self::PRO_UNA_VIRGINE => _("For One Virgin"),
/**translators: context = from the Common of nn: nn */
self::PRO_PLURIBUS_VIRGINIBUS => _("For Several Virgins"),
/**translators: context = from the Common of nn: nn */
self::PRO_PLURIBUS_SANCTIS => _("For Several Saints"),
/**translators: context = from the Common of nn: nn */
self::PRO_UNO_SANCTO => _("For One Saint"),
/**translators: context = from the Common of nn: nn */
self::PRO_ABBATE => _("For an Abbot"),
/**translators: context = from the Common of nn: nn */
self::PRO_MONACHO => _("For a Monk"),
/**translators: context = from the Common of nn: nn */
self::PRO_MONIALI => _("For a Nun"),
/**translators: context = from the Common of nn: nn */
self::PRO_RELIGIOSIS => _("For Religious"),
/**translators: context = from the Common of nn: nn */
self::PRO_IIS_QUI_OPERA_MISERICORDIAE_EXERCUERUNT => _("For Those Who Practiced Works of Mercy"),
/**translators: context = from the Common of nn: nn */
self::PRO_EDUCATORIBUS => _("For Educators"),
/**translators: context = from the Common of nn: nn */
self::PRO_SANCTIS_MULIERIBUS => _("For Holy Women")
];
}
public const LATIN = [
self::PROPRIO => "Proprio",
self::DEDICATIONIS_ECCLESIAE => "Dedicationis ecclesiæ",
self::BEATAE_MARIAE_VIRGINIS => "Beatæ Mariæ Virginis",
self::MARTYRUM => "Martyrum",
self::PASTORUM => "Pastorum",
self::DOCTORUM => "Doctorum",
self::VIRGINUM => "Virginum",
self::SANCTORUM_ET_SANCTARUM => "Sanctorum et Sanctarum",
self::PRO_UNO_MARTYRE => "Pro uno martyre",
self::PRO_PLURIBUS_MARTYRIBUS => "Pro pluribus martyribus",
self::PRO_MISSIONARIIS_MARTYRIBUS => "Pro missionariis martyribus",
self::PRO_UNO_MISSIONARIO_MARTYRE => "Pro uno missionario martyre",
self::PRO_PLURIBUS_MISSIONARIIS_MARTYRIBUS => "Pro pluribus missionariis martyribus",
self::PRO_VIRGINE_MARTYRE => "Pro virgine martyre",
self::PRO_SANCTA_MULIERE_MARTYRE => "Pro sancta muliere martyre",
self::PRO_PAPA => "Pro papa",
self::PRO_EPISCOPO => "Pro episcopo",
self::PRO_UNO_PASTORE => "Pro uno pastore",
self::PRO_PLURIBUS_PASTORIBUS => "Pro pluribus pastoribus",
self::PRO_FUNDATORIBUS_ECCLESIARUM => "Pro fundatoribus ecclesiarum",
self::PRO_UNO_FUNDATORE => "Pro uno fundatore",
self::PRO_PLURIBUS_FUNDATORIBUS => "Pro pluribus fundatoribus",
self::PRO_MISSIONARIIS => "Pro missionariis",
self::PRO_UNA_VIRGINE => "Pro una virgine",
self::PRO_PLURIBUS_VIRGINIBUS => "Pro pluribus virginibus",
self::PRO_PLURIBUS_SANCTIS => "Pro pluribus sanctis",
self::PRO_UNO_SANCTO => "Pro uno sancto",
self::PRO_ABBATE => "Pro abbate",
self::PRO_MONACHO => "Pro monacho",
self::PRO_MONIALI => "Pro moniali",
self::PRO_RELIGIOSIS => "Pro religiosis",
self::PRO_IIS_QUI_OPERA_MISERICORDIAE_EXERCUERUNT => "Pro iis qui opera misericordiae exercuerunt",
self::PRO_EDUCATORIBUS => "Pro educatoribus",
self::PRO_SANCTIS_MULIERIBUS => "Pro sanctis mulieribus"
];
public static function POSSESSIVE(string $value): string
{
switch ($value) {
case "Blessed Virgin Mary":
/**translators: (singular feminine) glue between "From the Common" and the actual common. Latin: leave empty! */
return pgettext("(SING_FEMM)", "of the");
case "Virgins":
/**translators: (plural feminine) glue between "From the Common" and the actual common. Latin: leave empty! */
return pgettext("(PLUR_FEMM)", "of");
case "Martyrs":
case "Pastors":
case "Doctors":
case "Holy Men and Women":
/**translators: (plural masculine) glue between "From the Common" and the actual common. Latin: leave empty! */
return pgettext("(PLUR_MASC)", "of");
case "Dedication of a Church":
/**translators: (singular feminine) glue between "From the Common" and the actual common. Latin: leave empty! */
return pgettext("(SING_FEMM)", "of the");
default:
/**translators: (singular masculine) glue between "From the Common" and the actual common. Latin: leave empty! */
return pgettext("(SING_MASC)", "of the");
}
}
public static array $values = [
"Proper",
"Dedication of a Church",
"Blessed Virgin Mary",
"Martyrs",
"Pastors",
"Doctors",
"Virgins",
"Holy Men and Women",
"For One Martyr",
"For Several Martyrs",
"For Missionary Martyrs",
"For One Missionary Martyr",
"For Several Missionary Martyrs",
"For a Virgin Martyr",
"For a Holy Woman Martyr",
"For a Pope",
"For a Bishop",
"For One Pastor",
"For Several Pastors",
"For Founders of a Church",
"For One Founder",
"For Several Founders",
"For Missionaries",
"For One Virgin",
"For Several Virgins",
"For Several Saints",
"For One Saint",
"For an Abbot",
"For a Monk",
"For a Nun",
"For Religious",
"For Those Who Practiced Works of Mercy",
"For Educators",
"For Holy Women"
];
public static function isValid(string $value)
{
if (strpos($value, ',') || strpos($value, ':')) {
$values = preg_split('/[,:]/', $value);
return self::areValid($values);
}
return in_array($value, self::$values);
}
public static function areValid(array $values)
{
$values = array_reduce($values, function ($carry, $key) {
return strpos($key, ':') ? ( $carry + explode(':', $key) ) : ( [ ...$carry, $key ] );
}, []);
return empty(array_diff($values, self::$values));
}
public function i18n(string|array $value): string|array
{
if (is_array($value) && self::areValid($value)) {
return array_map([$this, 'i18n'], $value);
} elseif (self::isValid($value)) {
if ($this->locale === LitLocale::LATIN) {
return self::LATIN[ $value ];
} else {
return $this->GTXT[ $value ];
}
}
return $value;
}
public function getPossessive(string|array $value): string|array
{
if (is_array($value)) {
return array_map([$this, 'getPossessive'], $value);
}
return $this->locale === LitLocale::LATIN ? "" : self::POSSESSIVE($value);
}
/**
* Function C
* Returns a translated human readable string of the Common or the Proper
*/
public function c(string|array $common = ""): string|array
{
if (( is_string($common) && $common !== "" ) || is_array($common)) {
if ((is_string($common) && $common === LitCommon::PROPRIO) || ( is_array($common) && in_array(LitCommon::PROPRIO, $common) )) {
$common = $this->locale === LitLocale::LATIN ? "De Proprio" : _("From the Proper of the festivity");
} else {
if (is_string($common)) {
$commons = explode(",", $common);
} else {
$commons = $common;
}
$commons = array_map(function ($txt) {
if (strpos($txt, ":") !== false) {
[$commonGeneral, $commonSpecific] = explode(":", $txt);
} else {
$commonGeneral = $txt;
$commonSpecific = "";
}
$fromTheCommon = $this->locale === LitLocale::LATIN ? "De Commune" : _("From the Common");
return $fromTheCommon . " " . $this->getPossessive($commonGeneral) . " " . $this->i18n($commonGeneral) . ($commonSpecific != "" ? ": " . $this->i18n($commonSpecific) : "");
}, $commons);
/**translators: when there are multiple possible commons, this will be the glue "or from the common of..." */
$common = implode("; " . _("or") . " ", $commons);
}
}
return $common;
}
}