PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.2.1
GiveWP – Donation Plugin and Fundraising Platform v2.2.1
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / class-give-translation.php
give / includes Last commit date
admin 7 years ago api 7 years ago deprecated 7 years ago donors 7 years ago emails 7 years ago forms 7 years ago gateways 7 years ago libraries 7 years ago payments 7 years ago actions.php 7 years ago ajax-functions.php 7 years ago class-give-async-process.php 8 years ago class-give-background-updater.php 7 years ago class-give-cache.php 7 years ago class-give-cli-commands.php 8 years ago class-give-comment.php 7 years ago class-give-cron.php 8 years ago class-give-db-donor-meta.php 8 years ago class-give-db-donors.php 7 years ago class-give-db-form-meta.php 8 years ago class-give-db-logs-meta.php 8 years ago class-give-db-logs.php 7 years ago class-give-db-meta.php 7 years ago class-give-db-payment-meta.php 7 years ago class-give-db-sequential-ordering.php 7 years ago class-give-db-sessions.php 7 years ago class-give-db.php 8 years ago class-give-donate-form.php 8 years ago class-give-donor-wall-widget.php 7 years ago class-give-donor.php 7 years ago class-give-email-access.php 8 years ago class-give-html-elements.php 7 years ago class-give-license-handler.php 7 years ago class-give-logging.php 8 years ago class-give-readme-parser.php 8 years ago class-give-roles.php 8 years ago class-give-scripts.php 7 years ago class-give-session.php 7 years ago class-give-stats.php 8 years ago class-give-template-loader.php 8 years ago class-give-tooltips.php 8 years ago class-give-translation.php 8 years ago class-notices.php 7 years ago country-functions.php 8 years ago currency-functions.php 7 years ago error-tracking.php 8 years ago filters.php 7 years ago formatting.php 7 years ago import-functions.php 7 years ago install.php 7 years ago login-register.php 8 years ago misc-functions.php 7 years ago plugin-compatibility.php 8 years ago post-types.php 8 years ago price-functions.php 7 years ago process-donation.php 7 years ago shortcodes.php 7 years ago template-functions.php 8 years ago user-functions.php 7 years ago
class-give-translation.php
422 lines
1 <?php
2
3 /**
4 * Translations
5 *
6 * @package Give
7 * @subpackage Classes/Give_Stats
8 * @copyright Copyright (c) 2017, Give
9 * @license https://opensource.org/licenses/gpl-license GNU Public License
10 * @since 2.0
11 */
12 class Give_Translations {
13 /**
14 * Instance.
15 *
16 * @since 2.0
17 * @access private
18 * @var
19 */
20 private static $instance;
21
22 /**
23 * Text config.
24 *
25 * @since 2.0
26 * @access private
27 * @var
28 */
29 private static $text_configs = array();
30
31 /**
32 * Translated texts.
33 *
34 * @since 2.0
35 * @access private
36 * @var
37 */
38 private static $text_translations = array();
39
40 /**
41 * Singleton pattern.
42 *
43 * @since 2.0
44 * @access private
45 */
46 private function __construct() {
47 }
48
49
50 /**
51 * Get instance.
52 *
53 * @since 2.0
54 * @access public
55 * @return static
56 */
57 public static function get_instance() {
58 if ( null === static::$instance ) {
59 self::$instance = new static();
60 }
61
62 return self::$instance;
63 }
64
65 /**
66 * Setup
67 *
68 * @since 2.0
69 * @access public
70 */
71 public function setup() {
72 self::setup_hooks();
73 }
74
75 /**
76 * Setup hooks
77 *
78 * @since 2.0
79 * @access public
80 */
81 public function setup_hooks() {
82 add_action( 'init', array( $this, 'load_translated_texts' ), 999 );
83 }
84
85 /**
86 * Load translated texts.
87 *
88 * @since 2.0
89 * @access public
90 */
91 public function load_translated_texts() {
92 /**
93 * Filter the translated texts.
94 *
95 * @since 2.0
96 */
97 self::$text_translations = apply_filters(
98 'give_translated_texts',
99 self::$text_translations
100 );
101 }
102
103 /**
104 * Add text by group ( if any )
105 *
106 * @since 2.0
107 * @access public
108 *
109 * @param array $args
110 *
111 * @return bool|WP_Error false on success otherwise WP_Error object
112 */
113 public static function add_text( $args = array() ) {
114 $error = false;
115
116 // Set text params.
117 $args = wp_parse_args(
118 $args,
119 array(
120 'text' => '',
121 'id' => '',
122 'group' => '',
123 'type' => 'text',
124 )
125 );
126
127 try {
128 // Check for errors.
129 if ( empty( $args['text'] ) ) {
130 /* @var WP_Error $error */
131 $error = new WP_Error( 'EMPTY_TEXT', __( 'Empty string is not allowed.', 'give' ), $args );
132 throw new Exception( $error->get_error_message( 'EMPTY_TEXT' ) );
133
134 } elseif ( empty( $args['id'] ) ) {
135 /* @var WP_Error $error */
136 $error = new WP_Error( 'EMPTY_ID', __( 'Empty ID is not allowed.', 'give' ), $args );
137 throw new Exception( $error->get_error_message( 'EMPTY_ID' ) );
138
139 } elseif (
140 empty( $args['group'] ) &&
141 array_key_exists( $args['id'], self::$text_configs )
142 ) {
143 /* @var WP_Error $error */
144 $error = new WP_Error( 'TEXT_ID_ALREADY_EXIST', __( 'Text ID without a group already exists.', 'give' ), $args );
145 throw new Exception( $error->get_error_message( 'TEXT_ID_ALREADY_EXIST' ) );
146
147 } elseif (
148 ! empty( $args['group'] ) &&
149 ! empty( self::$text_configs[ $args['group'] ] ) &&
150 array_key_exists( $args['id'], self::$text_configs[ $args['group'] ] )
151 ) {
152 /* @var WP_Error $error */
153 $error = new WP_Error( 'TEXT_ID_WITHIN_GROUP_ALREADY_EXIST', __( 'Text ID within a group already exists.', 'give' ), $args );
154 throw new Exception( $error->get_error_message( 'TEXT_ID_WITHIN_GROUP_ALREADY_EXIST' ) );
155
156 }
157
158 // Add text.
159 if ( ! empty( $args['group'] ) ) {
160 self::$text_configs[ $args['group'] ][ $args['id'] ] = $args;
161 } else {
162 self::$text_configs[ $args['id'] ] = $args;
163 }
164 } catch ( Exception $e ) {
165 error_log( $e->getMessage() );
166 }// End try().
167
168 /**
169 * Filter the texts
170 *
171 * @since 2.0
172 */
173 self::$text_configs = apply_filters( 'give_texts', self::$text_configs );
174
175 return $error;
176 }
177
178 /**
179 * Add label by group ( if any )
180 *
181 * @since 2.0
182 * @access public
183 *
184 * @param array $args
185 *
186 * @return string
187 */
188 public static function add_label( $args = array() ) {
189 // Set text params.
190 $args = wp_parse_args(
191 $args,
192 array(
193 'text' => '',
194 'id' => '',
195 'group' => '',
196 )
197 );
198
199 $args['type'] = 'label';
200 $args['id'] = "{$args['id']}_label";
201
202 return self::add_text( $args );
203 }
204
205 /**
206 * Add tooltip by group ( if any )
207 *
208 * @since 2.0
209 * @access public
210 *
211 * @param array $args
212 *
213 * @return string
214 */
215 public static function add_tooltip( $args = array() ) {
216 // Set text params.
217 $args = wp_parse_args(
218 $args,
219 array(
220 'text' => '',
221 'id' => '',
222 'group' => '',
223 )
224 );
225
226 $args['type'] = 'tooltip';
227 $args['id'] = "{$args['id']}_tooltip";
228
229 return self::add_text( $args );
230 }
231
232 /**
233 * Add translation by group ( if any )
234 *
235 * @since 2.0
236 * @access public
237 *
238 * @param array 4args
239 *
240 * @return string
241 */
242 public static function add_translation( $args = array() ) {
243 $args = wp_parse_args(
244 $args,
245 array(
246 'id' => '',
247 'group' => '',
248 'text' => '',
249 )
250 );
251
252 // Bailout.
253 if ( empty( $args['id'] ) ) {
254 return;
255 }
256
257 if ( ! empty( $args['group'] ) ) {
258 self::$text_translations[ $args['group'] ][ $args['id'] ] = $args['text'];
259 } else {
260 self::$text_translations[ $args['id'] ] = $args['text'];
261 }
262 }
263
264 /**
265 * Get label translation by group ( if any )
266 *
267 * @since 2.0
268 * @access public
269 *
270 * @param string $id
271 * @param string $group
272 * @param string $text
273 *
274 * @return string
275 */
276 public static function add_label_translation( $id, $group = '', $text = '' ) {
277 return self::get_text( array(
278 'id' => "{$id}_label",
279 'group' => $group,
280 'text' => $text,
281 ) );
282 }
283
284 /**
285 * Get tooltip translation by group ( if any )
286 *
287 * @since 2.0
288 * @access public
289 *
290 * @param string $id
291 * @param string $group
292 * @param string $text
293 *
294 * @return string
295 */
296 public static function add_tooltip_translation( $id, $group = '', $text = '' ) {
297 return self::get_text( array(
298 'id' => "{$id}_label",
299 'group' => $group,
300 'text' => $text,
301 ) );
302 }
303
304 /**
305 * Get label by group ( if any )
306 *
307 * @since 2.0
308 * @access public
309 *
310 * @param string $id
311 * @param string $group
312 *
313 * @return string
314 */
315 public static function get_label( $id, $group = '' ) {
316 return self::get_text( array(
317 'id' => "{$id}_label",
318 'group' => $group,
319 'type' => 'label',
320 ) );
321 }
322
323 /**
324 * Get tooltip by group ( if any )
325 *
326 * @since 2.0
327 * @access public
328 *
329 * @param string $id
330 * @param string $group
331 *
332 * @return string
333 */
334 public static function get_tooltip( $id, $group = '' ) {
335 return self::get_text( array(
336 'id' => "{$id}_tooltip",
337 'group' => $group,
338 'type' => 'tooltip',
339 ) );
340 }
341
342 /**
343 * Get text by group
344 *
345 * @since 2.0
346 * @access public
347 *
348 * @param array $args
349 *
350 * @return string
351 */
352 public static function get_text( $args = array() ) {
353 $text = '';
354
355 // Bailout.
356 if ( empty( $args ) ) {
357 return $text;
358 }
359
360 // Setup args.
361 $args = wp_parse_args(
362 $args,
363 array(
364 'id' => '',
365 'group' => '',
366 'type' => 'text',
367 )
368 );
369
370 // Check if text exist.
371 if (
372 empty( $args['id'] ) ||
373 ( empty( $args['group'] ) && ! array_key_exists( $args['id'], self::$text_configs ) ) ||
374 ( ! empty( $args['group'] ) && ! empty( self::$text_configs[ $args['group'] ] ) && ! array_key_exists( $args['id'], self::$text_configs[ $args['group'] ] ) )
375 ) {
376 return $text;
377 }
378
379 // Get text value.
380 if (
381 ! empty( $args['group'] ) &&
382 array_key_exists( $args['group'], self::$text_configs )
383 ) {
384 $text = self::$text_configs[ $args['group'] ][ $args['id'] ]['text'];
385
386 // Get translated text if exist.
387 if (
388 ! empty( self::$text_translations ) &&
389 ! empty( self::$text_translations[ $args['group'] ] ) &&
390 array_key_exists( $args['id'], self::$text_translations[ $args['group'] ] )
391 ) {
392 $text = self::$text_translations[ $args['group'] ][ $args['id'] ];
393 }
394 } elseif (
395 empty( $args['group'] ) &&
396 array_key_exists( $args['id'], self::$text_configs )
397 ) {
398 $text = self::$text_configs[ $args['id'] ]['text'];
399
400 // Get translated text if exist.
401 if (
402 ! empty( self::$text_translations ) &&
403 array_key_exists( $args['id'], self::$text_translations )
404 ) {
405 $text = self::$text_translations[ $args['id'] ];
406 }
407 }
408
409 /**
410 * Filter the give text
411 *
412 * @since 2.0
413 */
414 $text = apply_filters( 'give_text', $text, $args, self::$text_configs, self::$text_translations );
415
416 return $text;
417 }
418 }
419
420 // Setup translations.
421 Give_Translations::get_instance()->setup();
422