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

Feature: add locale support for visual form builder #7710

Merged
merged 21 commits into from
Feb 18, 2025

Conversation

glaubersilva
Copy link
Contributor

@glaubersilva glaubersilva commented Feb 5, 2025

Resolves GIVE-2124

Description

This PR adds support for v3 forms to work with different locales through the use of multilingual plugins. As a bonus, it also allows the creation of new forms respecting the language selected in the WP admin bar through the selectors provided by the WPML and Polylang plugins.

How it's working?

Before, in the render() method of the BlockRenderController() class we are returning a div with some data attributes like data-form-url that are used in the frontend. Now we also are sending a new data-form-locale attribute to be used in the frontend for subsequent requests (donation-form-view, donation-form-view-preview, and donation-confirmation-receipt-view).

Why it works?

Because when the render() method of the BlockRenderController() class is triggered it has the right context of the selected locale, but the subsequent requests made to the server by the frontend (donation-form-view, donation-form-view-preview, and donation-confirmation-receipt-view) didn't have it before but now they have because the new locale attribute is passed alongside to the subsequent requests and retrieved back in the Give\Framework\Routes\Router class and then used in the views to make sure we are rendering them with the proper locale.

It was inspired by this feature from the Polylang Pro plugin: https://polylang.pro/doc/rest-api/

Affects

The v3 forms.

Visuals

V3 forms - multilingual plugins support

https://www.loom.com/share/99d359f094f4448194965d506ea937ef?sid=bddc70ff-5dee-48fd-a4a2-9b7345c1fbe7

[Bonus Feature] Creating new V3 forms respecting the language selected on the WPML language selector or Polylang Language selector

https://www.loom.com/share/bbd4328a2b2b409784dcce6d3ae3871d?sid=d9e31524-1437-4737-8e46-cfbf5a000ea4

Testing Instructions

V3 forms - multilingual plugins support

  1. Install WPML or Polylang plugin;
  2. Setup the plugin installed Previously to use two languages;
  3. Create two v3 forms, one for each language setup previously;
  4. Use Loco Translate to translate strings that can't be translated using the Visual Form Builder;
  5. Create a new page for the Language 1 and insert the proper form shortcode on it;
  6. Create a new page for the Language 2 and insert the proper form shortcode on it;
  7. Access the page of the Language 1 and make sure everything is being displayed as expected;
  8. Use the language selector provided by the plugin (on the frontend) to switch to the Language 2 page and make sure everything is being displayed as expected;

[Bonus Feature] Creating new V3 forms respecting the language selected on the WPML language selector or Polylang Language selector

  1. Install WPML or Polylang plugin;
  2. Setup the plugin installed Previously to use two languages;
  3. Use Loco Translate to translate strings that can't be translated using the Visual Form Builder;
  4. Go to the GiveWP > All Forms page;
  5. Select the wished language in the language selector localized in the WP admin bar;
  6. Click on "Add Form" and make sure the new form was created respecting the language selected previously.

Pre-review Checklist

  • Acceptance criteria satisfied and marked in related issue
  • Relevant @unreleased tags included in DocBlocks
  • Includes unit tests
  • Reviewed by the designer (if follows a design)
  • Self Review of code and UX completed

@glaubersilva glaubersilva self-assigned this Feb 5, 2025
@glaubersilva glaubersilva marked this pull request as ready for review February 7, 2025 15:44
@glaubersilva glaubersilva requested a review from kjohnson February 7, 2025 15:45
Copy link
Contributor

@kjohnson kjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glaubersilva I think we can simplify this by moving the locale switching higher up the request chain in the places where we are passing the locale from Request to Controller to View Model.

@glaubersilva
Copy link
Contributor Author

@kjohnson This is ready for re-review.

@kjohnson
Copy link
Contributor

kjohnson commented Feb 12, 2025

Looks like this broke a test:

Give\Tests\Unit\DonationForms\Endpoints\TestListDonationForms::testShouldReturnListWithSameData

+ 'edit' => '?locale=en_US'
- 'edit' => null

The edit link no longer matches. Was it previously null?

@glaubersilva
Copy link
Contributor Author

@kjohnson The broken test was fixed here: 920f146

This is ready for re-review.

@kjohnson
Copy link
Contributor

Copy link
Member

@rickalday rickalday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed manual QA tests.

@glaubersilva glaubersilva merged commit cd521e1 into develop Feb 18, 2025
20 checks passed
@glaubersilva glaubersilva deleted the feature/vfb-locale-support-GIVE-2124 branch February 18, 2025 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants