Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy form donation modal should display the correct recurring donation billing description #6519

Open
Genevieve-K opened this issue Jul 21, 2022 · 2 comments
Labels
keep-fresh "Keep Fresh" issues should not be marked as stale. type: bug Existing functionality is broken

Comments

@Genevieve-K
Copy link
Contributor

Genevieve-K commented Jul 21, 2022

User Story

As a donor in a language other than English, I want to make a recurring donation when the interval is > 1, for a period that not is the default one. The period displayed to the right of the amount displays the default period, not the chosen period.

Details

See https://feedback.givewp.com/bug-reports/p/legacy-form-donation-modal-should-display-the-correct-recurring-donation-billing

Expected Behavior

Example in French: the default is 'Tous les deux mois pendant 8 mois' (Every two months for 8 months). I choose 'an' (year).
Expected message to the right of the amount: 'Tous les deux ans pendant huit ans' (Every two years for 8 years)
Displayed message: 'Tous les deux mois pendant 8 mois'

Issue in give-recurring.js line 144:

the 'recurringPeriod' and 'currentRecurringPeriod' varaibles are English strings, and 'recurringPeriod' doesn't match in the query. We need to translate them.

To fix

In give-recurring-helpers.php: add the function give_recurring_get_pretty_plural_periods()

function give_recurring_get_pretty_plural_period( $period ) {

	$periods = give_recurring_get_pretty_plural_periods();
	$plural_period = isset( $periods[ $period ] ) ? $periods[ $period ] : '';
	return $plural_period;
}

function give_recurring_get_pretty_plural_periods() {

	return array(
		'day'     => __( 'days', 'give-recurring' ),
		'week'    => __( 'weeks', 'give-recurring' ),
		'month'   => __( 'months', 'give-recurring' ),
		'quarter' => __( 'quarters', 'give-recurring' ),
		'year'    => __( 'years', 'give-recurring' ),
	);
}

In give-recurring-scripts.php, initialize 'plural_periods' line 36:
'pretty_periods' => give_recurring_get_default_pretty_periods(),

In give-recurring.js, get this variable, and use it.

			var prettyPeriods = Give_Recurring_Vars.pretty_periods;
			var pluralPeriods = Give_Recurring_Vars.plural_periods;

			if ( $this.is( 'select' ) ) {
				recurringPeriodLabel = $this.closest( 'div.give-recurring-donors-choice' )
					.find( '.give-recurring-period' )
					.data( 'period-label' );
				recurringPeriod = $this.closest( 'div.give-recurring-donors-choice' )
					.find( '.give-recurring-period' )
					.data( 'period' );
			}

			// Replace texts in label only if donor can change the recurring period.
			if ( currentRecurringPeriod ) {
		//		recurringPeriodLabel = recurringPeriodLabel.replace( new RegExp( recurringPeriod, 'g' ), currentRecurringPeriod );
				recurringPeriodLabel = recurringPeriodLabel.replace( new RegExp( pluralPeriods[ recurringPeriod ], 'g' ), pluralPeriods[ currentRecurringPeriod ] );
				recurringPeriodLabel = recurringPeriodLabel.replace( new RegExp( prettyPeriods[ recurringPeriod ], 'g' ), prettyPeriods[ currentRecurringPeriod ] );
			}
@Genevieve-K Genevieve-K added the type: bug Existing functionality is broken label Jul 21, 2022
@Genevieve-K Genevieve-K changed the title Legacy form donation modal should display the correct recurring donation billing description[Broken functionality] should... Legacy form donation modal should display the correct recurring donation billing description Jul 21, 2022
@kjohnson kjohnson added the keep-fresh "Keep Fresh" issues should not be marked as stale. label Oct 17, 2022
@Genevieve-K
Copy link
Contributor Author

I reported this fix in GiveRecurring 2.1.0 and then minified the JS file.

@canny
Copy link

canny bot commented Nov 17, 2022

This issue has been linked to a Canny post: Legacy form donation modal should display the correct recurring donation billing description 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep-fresh "Keep Fresh" issues should not be marked as stale. type: bug Existing functionality is broken
Projects
None yet
Development

No branches or pull requests

2 participants