/
utils-i18n.php
315 lines (266 loc) · 8.79 KB
/
utils-i18n.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php
/**
* i18n Utilities
*
* @since 141111 First documented version.
* @copyright WebSharks, Inc. <http://www.websharks-inc.com>
* @license GNU General Public License, version 3
*/
namespace comment_mail // Root namespace.
{
if(!defined('WPINC')) // MUST have WordPress.
exit('Do NOT access this file directly: '.basename(__FILE__));
if(!class_exists('\\'.__NAMESPACE__.'\\utils_i18n'))
{
/**
* i18n Utilities
*
* @since 141111 First documented version.
*/
class utils_i18n extends abs_base
{
/**
* Action past tense translation.
*
* @since 141111 First documented version.
*
* @param string $action An action; e.g. `confirm`, `delete`, `unconfirm`, etc.
* @param string $transform Defaults to `lower`.
*
* @return string The string translation for the given `$action`.
*/
public function action_ed($action, $transform = 'lower')
{
$action = $i18n = strtolower(trim((string)$action));
switch($action) // Convert to past tense.
{
case 'reconfirm':
$i18n = __('reconfirmed', $this->plugin->text_domain);
break;
case 'confirm':
$i18n = __('confirmed', $this->plugin->text_domain);
break;
case 'unconfirm':
$i18n = __('unconfirmed', $this->plugin->text_domain);
break;
case 'suspend':
$i18n = __('suspended', $this->plugin->text_domain);
break;
case 'trash':
$i18n = __('trashed', $this->plugin->text_domain);
break;
case 'update':
$i18n = __('updated', $this->plugin->text_domain);
break;
case 'delete':
$i18n = __('deleted', $this->plugin->text_domain);
break;
default: // Default case handler.
if($action) // Only if it's not empty.
$i18n = __(rtrim($action, 'ed').'ed', $this->plugin->text_domain);
break;
}
if(ctype_alnum($i18n)) switch($transform)
{
case 'lower':
$i18n = strtolower($i18n);
break;
case 'upper':
$i18n = strtoupper($i18n);
break;
case 'ucwords':
$i18n = ucwords($i18n);
break;
}
return $i18n;
}
/**
* Status label translation.
*
* @since 141111 First documented version.
*
* @param string $status A status e.g. `approve`, `hold`, `unconfirmed`, etc.
*
* @return string The string translation for the given `$status`.
*/
public function status_label($status)
{
$status = strtolower(trim((string)$status));
switch($status) // Convert to label.
{
case 'approve':
return __('approved', $this->plugin->text_domain);
case 'hold':
return __('pending', $this->plugin->text_domain);
case 'trash':
return __('trashed', $this->plugin->text_domain);
case 'spam':
return __('spammy', $this->plugin->text_domain);
case 'delete':
return __('deleted', $this->plugin->text_domain);
case 'open':
return __('open', $this->plugin->text_domain);
case 'closed':
return __('closed', $this->plugin->text_domain);
case 'unconfirmed':
return __('unconfirmed', $this->plugin->text_domain);
case 'subscribed':
return __('subscribed', $this->plugin->text_domain);
case 'suspended':
return __('suspended', $this->plugin->text_domain);
case 'trashed':
return __('trashed', $this->plugin->text_domain);
}
return !$status ? '' : __(rtrim($status, 'ed').'ed', $this->plugin->text_domain);
}
/**
* Event label translation.
*
* @since 141111 First documented version.
*
* @param string $event An event e.g. `inserted`, `updated`, `deleted`, etc.
*
* @return string The string translation for the given `$event`.
*/
public function event_label($event)
{
$event = strtolower(trim((string)$event));
switch($event) // Convert to label.
{
case 'inserted':
return __('inserted', $this->plugin->text_domain);
case 'updated':
return __('updated', $this->plugin->text_domain);
case 'overwritten':
return __('overwritten', $this->plugin->text_domain);
case 'purged':
return __('purged', $this->plugin->text_domain);
case 'cleaned':
return __('cleaned', $this->plugin->text_domain);
case 'deleted':
return __('deleted', $this->plugin->text_domain);
case 'invalidated':
return __('invalidated', $this->plugin->text_domain);
case 'notified':
return __('notified', $this->plugin->text_domain);
}
return !$event ? '' : __(rtrim($event, 'ed').'ed', $this->plugin->text_domain);
}
/**
* Deliver option label translation.
*
* @since 141111 First documented version.
*
* @param string $deliver A delivery option; e.g. `asap`, `hourly`, etc.
*
* @return string The string translation for the given `$deliver` option.
*/
public function deliver_label($deliver)
{
$deliver = strtolower(trim((string)$deliver));
switch($deliver) // Convert to label.
{
case 'asap':
return __('asap', $this->plugin->text_domain);
case 'hourly':
return __('hourly', $this->plugin->text_domain);
case 'daily':
return __('daily', $this->plugin->text_domain);
case 'weekly':
return __('weekly', $this->plugin->text_domain);
}
return !$deliver ? '' : __($deliver, $this->plugin->text_domain);
}
/**
* Sub. type label translation.
*
* @since 141111 First documented version.
*
* @param string $sub_type A sub. type; i.e. `comments`, `comment`.
*
* @return string The string translation for the given `$sub_type`.
*/
public function sub_type_label($sub_type)
{
$sub_type = strtolower(trim((string)$sub_type));
switch($sub_type) // Convert to label.
{
case 'comments':
return __('all comments', $this->plugin->text_domain);
case 'comment':
return __('replies only', $this->plugin->text_domain);
}
return !$sub_type ? '' : __($sub_type, $this->plugin->text_domain);
}
/**
* `X subscription` or `X subscriptions`.
*
* @since 141111 First documented version.
*
* @param integer $counter Total subscriptions; i.e. a counter value.
*
* @return string The phrase `X subscription` or `X subscriptions`.
*/
public function subscriptions($counter)
{
$counter = (integer)$counter; // Force integer.
return sprintf(_n('%1$s subscription', '%1$s subscriptions', $counter, $this->plugin->text_domain), $counter);
}
/**
* `X sub. event log entry` or `X sub. event log entries`.
*
* @since 141111 First documented version.
*
* @param integer $counter Total sub. event log entries; i.e. a counter value.
*
* @return string The phrase `X sub. event log entry` or `X sub. event log entries`.
*/
public function sub_event_log_entries($counter)
{
$counter = (integer)$counter; // Force integer.
return sprintf(_n('%1$s sub. event log entry', '%1$s sub. event log entries', $counter, $this->plugin->text_domain), $counter);
}
/**
* `X queued notification` or `X queued notifications`.
*
* @since 141111 First documented version.
*
* @param integer $counter Total queued notifications; i.e. a counter value.
*
* @return string The phrase `X queued notification` or `X queued notifications`.
*/
public function queued_notifications($counter)
{
$counter = (integer)$counter; // Force integer.
return sprintf(_n('%1$s queued notification', '%1$s queued notifications', $counter, $this->plugin->text_domain), $counter);
}
/**
* `X queue event log entry` or `X queue event log entries`.
*
* @since 141111 First documented version.
*
* @param integer $counter Total queue event log entries; i.e. a counter value.
*
* @return string The phrase `X queue event log entry` or `X queue event log entries`.
*/
public function queue_event_log_entries($counter)
{
$counter = (integer)$counter; // Force integer.
return sprintf(_n('%1$s queue event log entry', '%1$s queue event log entries', $counter, $this->plugin->text_domain), $counter);
}
/**
* A confirmation/warning regarding log entry deletions.
*
* @since 141111 First documented version.
*
* @return string Confirmation/warning regarding log entry deletions.
*/
public function log_entry_js_deletion_confirmation_warning()
{
return __('Delete permanently? Are you sure?', $this->plugin->text_domain)."\n\n".
__('WARNING: Deleting log entries is not recommended, as this will have an impact on statistical reporting.', $this->plugin->text_domain)."\n\n".
__('If you want statistical reports to remain accurate, please leave ALL log entries intact.', $this->plugin->text_domain);
}
}
}
}