PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.7.4
GiveWP – Donation Plugin and Fundraising Platform v2.7.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 5 years ago api 6 years ago database 6 years ago deprecated 6 years ago donors 5 years ago emails 6 years ago forms 6 years ago frontend 6 years ago gateways 6 years ago libraries 6 years ago payments 6 years ago actions.php 6 years ago ajax-functions.php 6 years ago class-give-async-process.php 6 years ago class-give-background-updater.php 6 years ago class-give-cache-setting.php 6 years ago class-give-cache.php 6 years ago class-give-cli-commands.php 6 years ago class-give-comment.php 6 years ago class-give-cron.php 6 years ago class-give-donate-form.php 6 years ago class-give-donor.php 6 years ago class-give-email-access.php 6 years ago class-give-license-handler.php 6 years ago class-give-logging.php 6 years ago class-give-readme-parser.php 6 years ago class-give-roles.php 6 years ago class-give-scripts.php 6 years ago class-give-session.php 6 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 6 years ago class-notices.php 6 years ago country-functions.php 6 years ago currencies-list.php 6 years ago currency-functions.php 6 years ago error-tracking.php 6 years ago filters.php 6 years ago formatting.php 6 years ago install.php 6 years ago login-register.php 6 years ago misc-functions.php 5 years ago plugin-compatibility.php 6 years ago post-types.php 6 years ago price-functions.php 6 years ago process-donation.php 6 years ago setting-functions.php 6 years ago shortcodes.php 6 years ago template-functions.php 6 years ago user-functions.php 6 years ago
class-give-translation.php
430 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(
278 array(
279 'id' => "{$id}_label",
280 'group' => $group,
281 'text' => $text,
282 )
283 );
284 }
285
286 /**
287 * Get tooltip translation by group ( if any )
288 *
289 * @since 2.0
290 * @access public
291 *
292 * @param string $id
293 * @param string $group
294 * @param string $text
295 *
296 * @return string
297 */
298 public static function add_tooltip_translation( $id, $group = '', $text = '' ) {
299 return self::get_text(
300 array(
301 'id' => "{$id}_label",
302 'group' => $group,
303 'text' => $text,
304 )
305 );
306 }
307
308 /**
309 * Get label by group ( if any )
310 *
311 * @since 2.0
312 * @access public
313 *
314 * @param string $id
315 * @param string $group
316 *
317 * @return string
318 */
319 public static function get_label( $id, $group = '' ) {
320 return self::get_text(
321 array(
322 'id' => "{$id}_label",
323 'group' => $group,
324 'type' => 'label',
325 )
326 );
327 }
328
329 /**
330 * Get tooltip by group ( if any )
331 *
332 * @since 2.0
333 * @access public
334 *
335 * @param string $id
336 * @param string $group
337 *
338 * @return string
339 */
340 public static function get_tooltip( $id, $group = '' ) {
341 return self::get_text(
342 array(
343 'id' => "{$id}_tooltip",
344 'group' => $group,
345 'type' => 'tooltip',
346 )
347 );
348 }
349
350 /**
351 * Get text by group
352 *
353 * @since 2.0
354 * @access public
355 *
356 * @param array $args
357 *
358 * @return string
359 */
360 public static function get_text( $args = array() ) {
361 $text = '';
362
363 // Bailout.
364 if ( empty( $args ) ) {
365 return $text;
366 }
367
368 // Setup args.
369 $args = wp_parse_args(
370 $args,
371 array(
372 'id' => '',
373 'group' => '',
374 'type' => 'text',
375 )
376 );
377
378 // Check if text exist.
379 if (
380 empty( $args['id'] ) ||
381 ( empty( $args['group'] ) && ! array_key_exists( $args['id'], self::$text_configs ) ) ||
382 ( ! empty( $args['group'] ) && ! empty( self::$text_configs[ $args['group'] ] ) && ! array_key_exists( $args['id'], self::$text_configs[ $args['group'] ] ) )
383 ) {
384 return $text;
385 }
386
387 // Get text value.
388 if (
389 ! empty( $args['group'] ) &&
390 array_key_exists( $args['group'], self::$text_configs )
391 ) {
392 $text = self::$text_configs[ $args['group'] ][ $args['id'] ]['text'];
393
394 // Get translated text if exist.
395 if (
396 ! empty( self::$text_translations ) &&
397 ! empty( self::$text_translations[ $args['group'] ] ) &&
398 array_key_exists( $args['id'], self::$text_translations[ $args['group'] ] )
399 ) {
400 $text = self::$text_translations[ $args['group'] ][ $args['id'] ];
401 }
402 } elseif (
403 empty( $args['group'] ) &&
404 array_key_exists( $args['id'], self::$text_configs )
405 ) {
406 $text = self::$text_configs[ $args['id'] ]['text'];
407
408 // Get translated text if exist.
409 if (
410 ! empty( self::$text_translations ) &&
411 array_key_exists( $args['id'], self::$text_translations )
412 ) {
413 $text = self::$text_translations[ $args['id'] ];
414 }
415 }
416
417 /**
418 * Filter the give text
419 *
420 * @since 2.0
421 */
422 $text = apply_filters( 'give_text', $text, $args, self::$text_configs, self::$text_translations );
423
424 return $text;
425 }
426 }
427
428 // Setup translations.
429 Give_Translations::get_instance()->setup();
430