diff --git a/give.php b/give.php index 5faa31f229..4180202bd8 100644 --- a/give.php +++ b/give.php @@ -68,6 +68,7 @@ use Give\Framework\PaymentGateways\PaymentGatewayRegister; use Give\Framework\ValidationRules\ValidationRulesServiceProvider; use Give\Framework\WordPressShims\ServiceProvider as WordPressShimsServiceProvider; +use Give\Helpers\Language; use Give\LegacySubscriptions\ServiceProvider as LegacySubscriptionsServiceProvider; use Give\License\LicenseServiceProvider; use Give\Log\LogServiceProvider; @@ -361,6 +362,7 @@ private function setup_constants() /** * Loads the plugin language files. * + * @unreleased Use Language class * @since 1.0 * @access public * @@ -368,17 +370,7 @@ private function setup_constants() */ public function load_textdomain() { - // Set filter for Give's languages directory - $give_lang_dir = dirname(plugin_basename(GIVE_PLUGIN_FILE)) . '/languages/'; - $give_lang_dir = apply_filters('give_languages_directory', $give_lang_dir); - - // Traditional WordPress plugin locale filter. - $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); - $locale = apply_filters('plugin_locale', $locale, 'give'); - - unload_textdomain('give'); - load_textdomain('give', WP_LANG_DIR . '/give/give-' . $locale . '.mo'); - load_plugin_textdomain('give', false, $give_lang_dir); + Language::load(); } /** diff --git a/globals.d.ts b/globals.d.ts index e1168d5a84..25867239f9 100644 --- a/globals.d.ts +++ b/globals.d.ts @@ -1,5 +1,5 @@ declare module '*.svg'; declare module '*.module.css'; declare module '*.module.scss'; - -declare module 'window.givewp.form.blocks'; +// this makes the wp or window.wp global variable available in the eyes of TypeScript +declare var wp; diff --git a/src/DonationForms/ViewModels/DonationConfirmationReceiptViewModel.php b/src/DonationForms/ViewModels/DonationConfirmationReceiptViewModel.php index 2da076e3c9..47c915c996 100644 --- a/src/DonationForms/ViewModels/DonationConfirmationReceiptViewModel.php +++ b/src/DonationForms/ViewModels/DonationConfirmationReceiptViewModel.php @@ -10,6 +10,7 @@ use Give\Framework\Receipts\DonationReceipt; use Give\Framework\Receipts\DonationReceiptBuilder; use Give\Framework\Support\Scripts\Concerns\HasScriptAssetFile; +use Give\Helpers\Language; /** * @since 3.0.0 @@ -92,7 +93,7 @@ public function render(): string $donationForm = !$donationFormRepository->isLegacyForm( $this->donation->formId ) ? $this->getDonationForm() : null; - + $formDesignId = $donationForm ? $donationForm->settings->designId : DeveloperFormDesign::id(); $customCss = $donationForm && $donationForm->settings->customCss ? $donationForm->settings->customCss : null; $primaryColor = $donationForm ? $donationForm->settings->primaryColor : '#69B868'; @@ -147,7 +148,7 @@ public function enqueueGlobalStyles(string $primaryColor, string $secondaryColor 'givewp-global-form-styles', ":root { --givewp-primary-color:{$primaryColor}; - --givewp-secondary-color:{$secondaryColor}; + --givewp-secondary-color:{$secondaryColor}; }" ); @@ -168,14 +169,17 @@ public function enqueueGlobalStyles(string $primaryColor, string $secondaryColor */ private function enqueueFormScripts(int $formId, string $formDesignId) { + $handle = 'givewp-donation-form-registrars'; wp_enqueue_script( - 'givewp-donation-form-registrars', + $handle, GIVE_PLUGIN_URL . 'build/donationFormRegistrars.js', $this->getScriptAssetDependencies(GIVE_PLUGIN_DIR . 'build/donationFormRegistrars.asset.php'), GIVE_VERSION, true ); + Language::setScriptTranslations($handle); + wp_add_inline_script( 'givewp-donation-form-registrars', 'window.givewpDonationFormExports = ' . wp_json_encode($this->formExports()) . ';', diff --git a/src/DonationForms/ViewModels/DonationFormViewModel.php b/src/DonationForms/ViewModels/DonationFormViewModel.php index 00b068f7b0..6261424b9d 100644 --- a/src/DonationForms/ViewModels/DonationFormViewModel.php +++ b/src/DonationForms/ViewModels/DonationFormViewModel.php @@ -15,6 +15,7 @@ use Give\Framework\FormDesigns\Registrars\FormDesignRegistrar; use Give\Framework\Support\Scripts\Concerns\HasScriptAssetFile; use Give\Helpers\Hooks; +use Give\Helpers\Language; /** * @since 3.0.0 @@ -270,14 +271,17 @@ private function enqueueRegistrars() GIVE_VERSION ); + $handle = 'givewp-donation-form-registrars'; wp_enqueue_script( - 'givewp-donation-form-registrars', + $handle, GIVE_PLUGIN_URL . 'build/donationFormRegistrars.js', $this->getScriptAssetDependencies(GIVE_PLUGIN_DIR . 'build/donationFormRegistrars.asset.php'), GIVE_VERSION, true ); + Language::setScriptTranslations($handle); + wp_add_inline_script( 'givewp-donation-form-registrars', 'window.givewpDonationFormExports = ' . wp_json_encode($this->exports()) . ';', @@ -304,6 +308,7 @@ private function enqueueGateways(int $formId) } /** + * @unreleased Set script translations * @since 3.0.0 */ private function enqueueDesign(string $formDesignId) @@ -317,8 +322,9 @@ private function enqueueDesign(string $formDesignId) } if ($design->js()) { + $handle = 'givewp-form-design-' . $design::id(); wp_enqueue_script( - 'givewp-form-design-' . $design::id(), + $handle, $design->js(), array_merge( $design->dependencies(), @@ -326,6 +332,8 @@ private function enqueueDesign(string $formDesignId) ), true ); + + Language::setScriptTranslations($handle); } } } diff --git a/src/DonationForms/resources/registrars/templates/fields/Gateways.tsx b/src/DonationForms/resources/registrars/templates/fields/Gateways.tsx index 65beb55a90..ef827f501d 100644 --- a/src/DonationForms/resources/registrars/templates/fields/Gateways.tsx +++ b/src/DonationForms/resources/registrars/templates/fields/Gateways.tsx @@ -1,7 +1,7 @@ import {ErrorMessage} from '@hookform/error-message'; import type {GatewayFieldProps, GatewayOptionProps} from '@givewp/forms/propTypes'; import {ErrorBoundary} from 'react-error-boundary'; -import {__} from '@wordpress/i18n'; +import {__, sprintf} from '@wordpress/i18n'; import {useEffect, useMemo} from 'react'; import {createInterpolateElement} from '@wordpress/element'; @@ -146,7 +146,7 @@ function GatewayOption({gateway, defaultChecked, inputProps}: GatewayOptionProps return (
- {__( - 'Specify below the email address you want to send a test email to', - 'givewp' - )} +
+ {__('Specify below the email address you want to send a test email to', 'givewp')}
-- {__( - 'Preview the email message in your browser', - 'givewp' - )} +
+ {__('Preview the email message in your browser', 'givewp')}
{tag.desc}
+{tag.desc}