From 2154dc2f2c2795edcaff05162093da66613cb45f Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 21 Jun 2022 11:31:09 +0530 Subject: [PATCH] fix: make string translatable --- templates/shortcode-donor-wall.php | 211 +++++++++--------- templates/shortcode-goal.php | 342 +++++++++++++++-------------- wp-textdomain.js | 13 +- 3 files changed, 291 insertions(+), 275 deletions(-) diff --git a/templates/shortcode-donor-wall.php b/templates/shortcode-donor-wall.php index fe4cd53d03..cb1a207c33 100644 --- a/templates/shortcode-donor-wall.php +++ b/templates/shortcode-donor-wall.php @@ -4,19 +4,19 @@ */ // Exit if accessed directly. -if ( ! defined( 'ABSPATH' ) ) { - exit; +if (!defined('ABSPATH')) { + exit; } /** @var $donor Give_Donor */ $donation = $args[0]; $give_settings = $args[1]; // Give settings. -$atts = $args[2]; // Shortcode attributes. +$atts = $args[2]; // Shortcode attributes. $primary_color = $atts['color']; -$avatarSize = (int) $atts['avatar_size'] ; -$tribute_background_color = ! empty( $atts['color']) ? $atts['color'] . '20' :'#219653'; +$avatarSize = (int)$atts['avatar_size']; +$tribute_background_color = !empty($atts['color']) ? $atts['color'] . '20' : '#219653'; ?> @@ -24,150 +24,153 @@
- $alt
"; - - } elseif( $donation['_give_payment_donor_email'] && give_validate_gravatar($donation['_give_payment_donor_email'])) { - // Donor has a valid Gravatar - $hash = md5( strtolower( trim( $donation['_give_payment_donor_email'] ) ) ); + } elseif ($donation['_give_payment_donor_email'] && give_validate_gravatar( + $donation['_give_payment_donor_email'] + )) { + // Donor has a valid Gravatar + $hash = md5(strtolower(trim($donation['_give_payment_donor_email']))); - echo " + echo "
$donor->name
"; + } else { + // Everyone else - } else { - // Everyone else - - $initial = esc_html($donation['name_initial']); - echo " + $initial = esc_html($donation['name_initial']); + echo "
$initial
"; - } } - ?> - - -

'> - - -

- - - -

- -

- - - + + +

'> + + +

+ + + +

+ +

+ + +
-
+
$excerpt … $read_more_text

"; echo "

$comment

"; - } ?>
- -
-
- $full_form_name "; - } - else { - echo " $truncated_form_name "; - } - } - - // Display full form name if ['show_total'] is false - else if ($atts['show_form'] && ! $atts['show_total'] && isset( $donation['_give_payment_form_title'] ) ) { - echo " $full_form_name "; - } + +
+
+ $full_form_name "; + } else { + echo " $truncated_form_name "; + } + } // Display full form name if ['show_total'] is false + else { + if ($atts['show_form'] && !$atts['show_total'] && isset($donation['_give_payment_form_title'])) { + echo " $full_form_name "; + } + } - if ($atts['show_total'] ) { - echo "Amount Donated"; + if ($atts['show_total']) { + echo sprintf( + '%1$s', + esc_html__('Amount Donated', 'give') + ); } - ?> -
+ ?> +
$donation_amount "; - } - ?> -
+ } + ?>
+
+ "
@@ -195,7 +198,7 @@ $honoree_full_name
"; - } + } ?>
diff --git a/templates/shortcode-goal.php b/templates/shortcode-goal.php index b15ef9f908..3d28d2ac8a 100644 --- a/templates/shortcode-goal.php +++ b/templates/shortcode-goal.php @@ -3,70 +3,68 @@ * This template is used to display the goal with [give_goal] */ -$form = new Give_Donate_Form( $form_id ); -$goal_option = give_get_meta( $form->ID, '_give_goal_option', true ); +$form = new Give_Donate_Form($form_id); +$goal_option = give_get_meta($form->ID, '_give_goal_option', true); // Sanity check - ensure form has pass all condition to show goal. -if ( ( isset( $args['show_goal'] ) && ! filter_var( $args['show_goal'], FILTER_VALIDATE_BOOLEAN ) ) - || empty( $form->ID ) - || ( is_singular( 'give_forms' ) && ! give_is_setting_enabled( $goal_option ) ) - || ! give_is_setting_enabled( $goal_option ) || 0 === $form->goal ) { - return false; +if ((isset($args['show_goal']) && !filter_var($args['show_goal'], FILTER_VALIDATE_BOOLEAN)) + || empty($form->ID) + || (is_singular('give_forms') && !give_is_setting_enabled($goal_option)) + || !give_is_setting_enabled($goal_option) || 0 === $form->goal) { + return false; } -$goal_progress_stats = give_goal_progress_stats( $form ); -$goal_format = $goal_progress_stats['format']; -$color = $args['progress_bar_color']; -$show_text = isset( $args['show_text'] ) ? filter_var( $args['show_text'], FILTER_VALIDATE_BOOLEAN ) : true; -$show_bar = isset( $args['show_bar'] ) ? filter_var( $args['show_bar'], FILTER_VALIDATE_BOOLEAN ) : true; +$goal_progress_stats = give_goal_progress_stats($form); +$goal_format = $goal_progress_stats['format']; +$color = $args['progress_bar_color']; +$show_text = isset($args['show_text']) ? filter_var($args['show_text'], FILTER_VALIDATE_BOOLEAN) : true; +$show_bar = isset($args['show_bar']) ? filter_var($args['show_bar'], FILTER_VALIDATE_BOOLEAN) : true; /** * Allow filtering the goal stats used for this shortcode context. * * @unreleased * - * @param array $stats The income and goal values for this form goal. - * @param int $form_id Donation Form ID. - * @param array $goal_progress_stats The full goal progress stats. - * @param array $args The full list of shortcode arguments passed. + * @param array $stats The income and goal values for this form goal. + * @param int $form_id Donation Form ID. + * @param array $goal_progress_stats The full goal progress stats. + * @param array $args The full list of shortcode arguments passed. */ $shortcode_stats = apply_filters( 'give_goal_shortcode_stats', - array( + [ 'income' => $form->get_earnings(), - 'goal' => $goal_progress_stats['raw_goal'], - ), + 'goal' => $goal_progress_stats['raw_goal'], + ], $form_id, $goal_progress_stats, $args ); $income = $shortcode_stats['income']; -$goal = $shortcode_stats['goal']; +$goal = $shortcode_stats['goal']; -switch ( $goal_format ) { - +switch ($goal_format) { case 'donation': - $progress = $goal ? round( ( $form->get_sales() / $goal ) * 100, 2 ) : 0; + $progress = $goal ? round(($form->get_sales() / $goal) * 100, 2) : 0; $progress_bar_value = $form->get_sales() >= $goal ? 100 : $progress; break; case 'donors': - $progress = $goal ? round( ( give_get_form_donor_count( $form->ID ) / $goal ) * 100, 2 ) : 0; - $progress_bar_value = give_get_form_donor_count( $form->ID ) >= $goal ? 100 : $progress; + $progress = $goal ? round((give_get_form_donor_count($form->ID) / $goal) * 100, 2) : 0; + $progress_bar_value = give_get_form_donor_count($form->ID) >= $goal ? 100 : $progress; break; case 'percentage': - $progress = $goal ? round( ( $income / $goal ) * 100, 2 ) : 0; + $progress = $goal ? round(($income / $goal) * 100, 2) : 0; $progress_bar_value = $income >= $goal ? 100 : $progress; break; default: - $progress = $goal ? round( ( $income / $goal ) * 100, 2 ) : 0; + $progress = $goal ? round(($income / $goal) * 100, 2) : 0; $progress_bar_value = $income >= $goal ? 100 : $progress; break; - } /** @@ -74,180 +72,192 @@ * * @since 1.8.8 */ -$progress = apply_filters( 'give_goal_amount_funded_percentage_output', $progress, $form_id, $form ); - +$progress = apply_filters('give_goal_amount_funded_percentage_output', $progress, $form_id, $form); ?>
-
-
+
- -
- false, - 'currency' => $form_currency, - 'decimal' => false, - ), - $form_id - ); - - /** - * Filter the goal formatting arguments. - * - * @since 1.8.17 - */ - $goal_format_args = apply_filters( - 'give_goal_amount_format_args', - array( - 'sanitize' => false, - 'currency' => $form_currency, - 'decimal' => false, - ), - $form_id - ); - - /** - * This filter will be used to convert the goal amounts to different currencies. - * - * @since 2.5.4 - * - * @param array $amounts List of goal amounts. - * @param int $form_id Donation Form ID. - */ - $goal_amounts = apply_filters( - 'give_goal_amounts', - array( - $form_currency => $goal, - ), - $form_id - ); - - /** - * This filter will be used to convert the income amounts to different currencies. - * - * @since 2.5.4 - * - * @param array $amounts List of goal amounts. - * @param int $form_id Donation Form ID. - */ - $income_amounts = apply_filters( - 'give_goal_raised_amounts', - array( - $form_currency => $income, - ), - $form_id - ); - - // Get human readable donation amount. - $income = give_human_format_large_amount( give_format_amount( $income, $income_format_args ), array( 'currency' => $form_currency ) ); - $goal = give_human_format_large_amount( give_format_amount( $goal, $goal_format_args ), array( 'currency' => $form_currency ) ); - - // Format the human readable donation amount. - $formatted_income = give_currency_filter( - $income, - array( - 'form_id' => $form_id, - ) - ); - - $formatted_goal = give_currency_filter( - $goal, - array( - 'form_id' => $form_id, - ) - ); - echo sprintf( - /* translators: 1: amount of income raised 2: goal target amount. */ - __( '
+ +
+ false, + 'currency' => $form_currency, + 'decimal' => false, + ], + $form_id + ); + + /** + * Filter the goal formatting arguments. + * + * @since 1.8.17 + */ + $goal_format_args = apply_filters( + 'give_goal_amount_format_args', + [ + 'sanitize' => false, + 'currency' => $form_currency, + 'decimal' => false, + ], + $form_id + ); + + /** + * This filter will be used to convert the goal amounts to different currencies. + * + * @since 2.5.4 + * + * @param array $amounts List of goal amounts. + * @param int $form_id Donation Form ID. + */ + $goal_amounts = apply_filters( + 'give_goal_amounts', + [ + $form_currency => $goal, + ], + $form_id + ); + + /** + * This filter will be used to convert the income amounts to different currencies. + * + * @since 2.5.4 + * + * @param array $amounts List of goal amounts. + * @param int $form_id Donation Form ID. + */ + $income_amounts = apply_filters( + 'give_goal_raised_amounts', + [ + $form_currency => $income, + ], + $form_id + ); + + // Get human readable donation amount. + $income = give_human_format_large_amount( + give_format_amount($income, $income_format_args), + ['currency' => $form_currency] + ); + $goal = give_human_format_large_amount( + give_format_amount($goal, $goal_format_args), + ['currency' => $form_currency] + ); + + // Format the human readable donation amount. + $formatted_income = give_currency_filter( + $income, + [ + 'form_id' => $form_id, + ] + ); + + $formatted_goal = give_currency_filter( + $goal, + [ + 'form_id' => $form_id, + ] + ); + echo sprintf( + /* translators: 1: amount of income raised 2: goal target amount. */ + __( + '
%2$s of %4$s -
', 'give' ), - esc_attr( wp_json_encode( $income_amounts, JSON_PRETTY_PRINT ) ), - esc_attr( $formatted_income ), - esc_attr( wp_json_encode( $goal_amounts, JSON_PRETTY_PRINT ) ), - esc_attr( $formatted_goal ) - ); +
', + 'give' + ), + esc_attr(wp_json_encode($income_amounts, JSON_PRETTY_PRINT)), + esc_attr($formatted_income), + esc_attr(wp_json_encode($goal_amounts, JSON_PRETTY_PRINT)), + esc_attr($formatted_goal) + ); - elseif ( 'percentage' === $goal_format ) : + elseif ('percentage' === $goal_format) : - echo sprintf( /* translators: %s: percentage of the amount raised compared to the goal target */ - __( '
+ echo sprintf( /* translators: %s: percentage of the amount raised compared to the goal target */ + __( + '
%s%% of 100% -
', 'give' ), - round( $progress ) - ); +
', + 'give' + ), + round($progress) + ); - elseif ( 'donation' === $goal_format ) : + elseif ('donation' === $goal_format) : - echo sprintf( /* translators: 1: total number of donations completed 2: total number of donations set as goal */ - _n( - '
+ echo sprintf( /* translators: 1: total number of donations completed 2: total number of donations set as goal */ + _n( + '
%s%% %2$s
', - '
+ '
%1$s of %2$s Donations
', - $goal, - 'give' - ), + $goal, + 'give' + ), $form->get_sales(), - give_format_amount( $goal, array( 'decimal' => false ) ) - ); + give_format_amount($goal, ['decimal' => false]) + ); - elseif ( 'donors' === $goal_format ) : + elseif ('donors' === $goal_format) : - echo sprintf( /* translators: 1: total number of donors completed 2: total number of donors set as goal */ - _n( - '
+ echo sprintf( /* translators: 1: total number of donors completed 2: total number of donors set as goal */ + _n( + '
%1$s - of %2$s Donors + %2$s
', - '
+ '
%1$s of %2$s Donors
', - $goal, - 'give' - ), - give_get_form_donor_count( $form->ID ), - give_format_amount( $goal, array( 'decimal' => false ) ) - ); - endif; - ?> + $goal, + 'give' + ), + give_get_form_donor_count($form->ID), + give_format_amount($goal, ['decimal' => false]) + ); + endif; + ?>
get_sales(); ?> - Donations +
-
- +
+
diff --git a/wp-textdomain.js b/wp-textdomain.js index 2febbecadb..30caca81f3 100644 --- a/wp-textdomain.js +++ b/wp-textdomain.js @@ -1,6 +1,9 @@ -const wpTextdomain = require( 'wp-textdomain' ); +const wpTextdomain = require('wp-textdomain'); -wpTextdomain( process.argv[ 2 ], { - domain: 'give', - fix: true, -} ); +wpTextdomain(process.argv[2], { + domain: 'give', + // fix: true, + 'glob': { + "ignore": ['vendor', 'languages', 'node_modules', 'assets', 'tests', 'sample-data', '.git', '.github'] + } +});