PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.19.4
GiveWP – Donation Plugin and Fundraising Platform v3.19.4
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 1 year ago api 3 years ago database 2 years ago deprecated 3 years ago donors 1 year ago emails 3 years ago forms 1 year ago frontend 6 years ago gateways 1 year ago libraries 2 years ago payments 1 year ago actions.php 5 years ago ajax-functions.php 2 years ago class-give-async-process.php 1 year ago class-give-background-updater.php 2 years ago class-give-cache-setting.php 2 years ago class-give-cache.php 3 years ago class-give-cli-commands.php 3 years ago class-give-comment.php 6 years ago class-give-cron.php 6 years ago class-give-donate-form.php 1 year ago class-give-donor.php 2 years ago class-give-email-access.php 5 years ago class-give-license-handler.php 1 year ago class-give-logging.php 5 years ago class-give-readme-parser.php 4 years ago class-give-roles.php 6 years ago class-give-scripts.php 2 years ago class-give-session.php 5 years ago class-give-stats.php 6 years ago class-give-template-loader.php 6 years ago class-give-tooltips.php 6 years ago class-give-translation.php 4 years ago class-notices.php 2 years ago country-functions.php 1 year ago currencies-list.php 3 years ago currency-functions.php 3 years ago error-tracking.php 6 years ago filters.php 3 years ago formatting.php 1 year ago install.php 2 years ago login-register.php 2 years ago misc-functions.php 1 year ago plugin-compatibility.php 6 years ago post-types.php 1 year ago price-functions.php 6 years ago process-donation.php 1 year ago setting-functions.php 6 years ago shortcodes.php 1 year ago template-functions.php 4 years ago user-functions.php 3 years ago
class-give-translation.php
432 lines
1 <?php
2
3 use Give\Log\Log;
4
5 /**
6 * Translations
7 *
8 * @package Give
9 * @subpackage Classes/Give_Stats
10 * @copyright Copyright (c) 2017, Give
11 * @license https://opensource.org/licenses/gpl-license GNU Public License
12 * @since 2.0
13 */
14 class Give_Translations {
15 /**
16 * Instance.
17 *
18 * @since 2.0
19 * @access private
20 * @var
21 */
22 private static $instance;
23
24 /**
25 * Text config.
26 *
27 * @since 2.0
28 * @access private
29 * @var
30 */
31 private static $text_configs = array();
32
33 /**
34 * Translated texts.
35 *
36 * @since 2.0
37 * @access private
38 * @var
39 */
40 private static $text_translations = array();
41
42 /**
43 * Singleton pattern.
44 *
45 * @since 2.0
46 * @access private
47 */
48 private function __construct() {
49 }
50
51
52 /**
53 * Get instance.
54 *
55 * @since 2.0
56 * @access public
57 * @return static
58 */
59 public static function get_instance() {
60 if ( null === static::$instance ) {
61 self::$instance = new static();
62 }
63
64 return self::$instance;
65 }
66
67 /**
68 * Setup
69 *
70 * @since 2.0
71 * @access public
72 */
73 public function setup() {
74 self::setup_hooks();
75 }
76
77 /**
78 * Setup hooks
79 *
80 * @since 2.0
81 * @access public
82 */
83 public function setup_hooks() {
84 add_action( 'init', array( $this, 'load_translated_texts' ), 999 );
85 }
86
87 /**
88 * Load translated texts.
89 *
90 * @since 2.0
91 * @access public
92 */
93 public function load_translated_texts() {
94 /**
95 * Filter the translated texts.
96 *
97 * @since 2.0
98 */
99 self::$text_translations = apply_filters(
100 'give_translated_texts',
101 self::$text_translations
102 );
103 }
104
105 /**
106 * Add text by group ( if any )
107 *
108 * @since 2.0
109 * @access public
110 *
111 * @param array $args
112 *
113 * @return bool|WP_Error false on success otherwise WP_Error object
114 */
115 public static function add_text( $args = array() ) {
116 $error = false;
117
118 // Set text params.
119 $args = wp_parse_args(
120 $args,
121 array(
122 'text' => '',
123 'id' => '',
124 'group' => '',
125 'type' => 'text',
126 )
127 );
128
129 try {
130 // Check for errors.
131 if ( empty( $args['text'] ) ) {
132 /* @var WP_Error $error */
133 $error = new WP_Error( 'EMPTY_TEXT', __( 'Empty string is not allowed.', 'give' ), $args );
134 throw new Exception( $error->get_error_message( 'EMPTY_TEXT' ) );
135 } elseif ( empty( $args['id'] ) ) {
136 /* @var WP_Error $error */
137 $error = new WP_Error( 'EMPTY_ID', __( 'Empty ID is not allowed.', 'give' ), $args );
138 throw new Exception( $error->get_error_message( 'EMPTY_ID' ) );
139
140 } elseif (
141 empty( $args['group'] ) &&
142 array_key_exists( $args['id'], self::$text_configs )
143 ) {
144 /* @var WP_Error $error */
145 $error = new WP_Error( 'TEXT_ID_ALREADY_EXIST', __( 'Text ID without a group already exists.', 'give' ), $args );
146 throw new Exception( $error->get_error_message( 'TEXT_ID_ALREADY_EXIST' ) );
147
148 } elseif (
149 ! empty( $args['group'] ) &&
150 ! empty( self::$text_configs[ $args['group'] ] ) &&
151 array_key_exists( $args['id'], self::$text_configs[ $args['group'] ] )
152 ) {
153 /* @var WP_Error $error */
154 $error = new WP_Error( 'TEXT_ID_WITHIN_GROUP_ALREADY_EXIST', __( 'Text ID within a group already exists.', 'give' ), $args );
155 throw new Exception( $error->get_error_message( 'TEXT_ID_WITHIN_GROUP_ALREADY_EXIST' ) );
156
157 }
158
159 // Add text.
160 if ( ! empty( $args['group'] ) ) {
161 self::$text_configs[ $args['group'] ][ $args['id'] ] = $args;
162 } else {
163 self::$text_configs[ $args['id'] ] = $args;
164 }
165 } catch ( Exception $e ) {
166 Log::error( $e->getMessage() );
167 }// End try().
168
169 /**
170 * Filter the texts
171 *
172 * @since 2.0
173 */
174 self::$text_configs = apply_filters( 'give_texts', self::$text_configs );
175
176 return $error;
177 }
178
179 /**
180 * Add label by group ( if any )
181 *
182 * @since 2.0
183 * @access public
184 *
185 * @param array $args
186 *
187 * @return string
188 */
189 public static function add_label( $args = array() ) {
190 // Set text params.
191 $args = wp_parse_args(
192 $args,
193 array(
194 'text' => '',
195 'id' => '',
196 'group' => '',
197 )
198 );
199
200 $args['type'] = 'label';
201 $args['id'] = "{$args['id']}_label";
202
203 return self::add_text( $args );
204 }
205
206 /**
207 * Add tooltip by group ( if any )
208 *
209 * @since 2.0
210 * @access public
211 *
212 * @param array $args
213 *
214 * @return string
215 */
216 public static function add_tooltip( $args = array() ) {
217 // Set text params.
218 $args = wp_parse_args(
219 $args,
220 array(
221 'text' => '',
222 'id' => '',
223 'group' => '',
224 )
225 );
226
227 $args['type'] = 'tooltip';
228 $args['id'] = "{$args['id']}_tooltip";
229
230 return self::add_text( $args );
231 }
232
233 /**
234 * Add translation by group ( if any )
235 *
236 * @since 2.0
237 * @access public
238 *
239 * @param array 4args
240 *
241 * @return string
242 */
243 public static function add_translation( $args = array() ) {
244 $args = wp_parse_args(
245 $args,
246 array(
247 'id' => '',
248 'group' => '',
249 'text' => '',
250 )
251 );
252
253 // Bailout.
254 if ( empty( $args['id'] ) ) {
255 return;
256 }
257
258 if ( ! empty( $args['group'] ) ) {
259 self::$text_translations[ $args['group'] ][ $args['id'] ] = $args['text'];
260 } else {
261 self::$text_translations[ $args['id'] ] = $args['text'];
262 }
263 }
264
265 /**
266 * Get label translation by group ( if any )
267 *
268 * @since 2.0
269 * @access public
270 *
271 * @param string $id
272 * @param string $group
273 * @param string $text
274 *
275 * @return string
276 */
277 public static function add_label_translation( $id, $group = '', $text = '' ) {
278 return self::get_text(
279 array(
280 'id' => "{$id}_label",
281 'group' => $group,
282 'text' => $text,
283 )
284 );
285 }
286
287 /**
288 * Get tooltip translation by group ( if any )
289 *
290 * @since 2.0
291 * @access public
292 *
293 * @param string $id
294 * @param string $group
295 * @param string $text
296 *
297 * @return string
298 */
299 public static function add_tooltip_translation( $id, $group = '', $text = '' ) {
300 return self::get_text(
301 array(
302 'id' => "{$id}_label",
303 'group' => $group,
304 'text' => $text,
305 )
306 );
307 }
308
309 /**
310 * Get label by group ( if any )
311 *
312 * @since 2.0
313 * @access public
314 *
315 * @param string $id
316 * @param string $group
317 *
318 * @return string
319 */
320 public static function get_label( $id, $group = '' ) {
321 return self::get_text(
322 array(
323 'id' => "{$id}_label",
324 'group' => $group,
325 'type' => 'label',
326 )
327 );
328 }
329
330 /**
331 * Get tooltip by group ( if any )
332 *
333 * @since 2.0
334 * @access public
335 *
336 * @param string $id
337 * @param string $group
338 *
339 * @return string
340 */
341 public static function get_tooltip( $id, $group = '' ) {
342 return self::get_text(
343 array(
344 'id' => "{$id}_tooltip",
345 'group' => $group,
346 'type' => 'tooltip',
347 )
348 );
349 }
350
351 /**
352 * Get text by group
353 *
354 * @since 2.0
355 * @access public
356 *
357 * @param array $args
358 *
359 * @return string
360 */
361 public static function get_text( $args = array() ) {
362 $text = '';
363
364 // Bailout.
365 if ( empty( $args ) ) {
366 return $text;
367 }
368
369 // Setup args.
370 $args = wp_parse_args(
371 $args,
372 array(
373 'id' => '',
374 'group' => '',
375 'type' => 'text',
376 )
377 );
378
379 // Check if text exist.
380 if (
381 empty( $args['id'] ) ||
382 ( empty( $args['group'] ) && ! array_key_exists( $args['id'], self::$text_configs ) ) ||
383 ( ! empty( $args['group'] ) && ! empty( self::$text_configs[ $args['group'] ] ) && ! array_key_exists( $args['id'], self::$text_configs[ $args['group'] ] ) )
384 ) {
385 return $text;
386 }
387
388 // Get text value.
389 if (
390 ! empty( $args['group'] ) &&
391 array_key_exists( $args['group'], self::$text_configs )
392 ) {
393 $text = self::$text_configs[ $args['group'] ][ $args['id'] ]['text'];
394
395 // Get translated text if exist.
396 if (
397 ! empty( self::$text_translations ) &&
398 ! empty( self::$text_translations[ $args['group'] ] ) &&
399 array_key_exists( $args['id'], self::$text_translations[ $args['group'] ] )
400 ) {
401 $text = self::$text_translations[ $args['group'] ][ $args['id'] ];
402 }
403 } elseif (
404 empty( $args['group'] ) &&
405 array_key_exists( $args['id'], self::$text_configs )
406 ) {
407 $text = self::$text_configs[ $args['id'] ]['text'];
408
409 // Get translated text if exist.
410 if (
411 ! empty( self::$text_translations ) &&
412 array_key_exists( $args['id'], self::$text_translations )
413 ) {
414 $text = self::$text_translations[ $args['id'] ];
415 }
416 }
417
418 /**
419 * Filter the give text
420 *
421 * @since 2.0
422 */
423 $text = apply_filters( 'give_text', $text, $args, self::$text_configs, self::$text_translations );
424
425 return $text;
426 }
427 }
428
429 // Setup translations.
430 Give_Translations::get_instance()->setup();
431
432