Skip to content

Commit

Permalink
Merge pull request #986 from mollie/fix/translation-error-in-blocks
Browse files Browse the repository at this point in the history
Fix/translation error in blocks
  • Loading branch information
mmaymo authored Jan 20, 2025
2 parents 96922db + a428402 commit 2e68334
Show file tree
Hide file tree
Showing 40 changed files with 454 additions and 103 deletions.
6 changes: 5 additions & 1 deletion .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mollie-payments-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ function initialize()
}
}

add_action('after_setup_theme', __NAMESPACE__ . '\\initialize');
add_action('plugins_loaded', __NAMESPACE__ . '\\initialize');
13 changes: 7 additions & 6 deletions src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,10 @@ static function () {

// Set order to paid and processed when eventually completed without Mollie
add_action('woocommerce_payment_complete', [$this, 'setOrderPaidByOtherGateway'], 10, 1);
$appleGateway = isset($container->get('gateway.instances')['mollie_wc_gateway_applepay']) ? $container->get(
'gateway.instances'
)['mollie_wc_gateway_applepay'] : false;

$surchargeService = $container->get(Surcharge::class);
assert($surchargeService instanceof Surcharge);
$this->gatewaySurchargeHandling($surchargeService);
$notice = $container->get(AdminNotice::class);
assert($notice instanceof AdminNotice);
$logger = $container->get(Logger::class);
Expand All @@ -297,9 +298,9 @@ static function () {
assert($apiHelper instanceof Api);
$settingsHelper = $container->get('settings.settings_helper');
assert($settingsHelper instanceof Settings);
$surchargeService = $container->get(Surcharge::class);
assert($surchargeService instanceof Surcharge);
$this->gatewaySurchargeHandling($surchargeService);
$appleGateway = isset($container->get('gateway.instances')['mollie_wc_gateway_applepay']) ? $container->get(
'gateway.instances'
)['mollie_wc_gateway_applepay'] : false;
if ($appleGateway) {
$this->mollieApplePayDirectHandling($notice, $logger, $apiHelper, $settingsHelper, $appleGateway);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Gateway/MolliePaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ public function __construct(
);
$this->supports = $this->paymentMethod->getProperty('supports');

// Load the settings.
$this->init_form_fields();
// Load the settings when translations are ready
add_action('init', [$this, 'init_form_fields']);

$this->init_settings();
$this->title = $this->paymentMethod->title();

Expand Down
20 changes: 20 additions & 0 deletions src/PaymentMethods/AbstractPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ abstract class AbstractPaymentMethod implements PaymentMethodI
* @var array
*/
private $apiPaymentMethod;
/**
* @var bool
*/
protected bool $translationsInitialized = false;

public function __construct(
IconFactory $iconFactory,
Expand All @@ -61,6 +65,8 @@ public function __construct(
$this->config = $this->getConfig();
$this->settings = $this->getSettings();
$this->apiPaymentMethod = $apiPaymentMethod;
add_action('init', [$this, 'initializeTranslations']);
add_action('init', [$this, 'updateSettingsWithDefaults']);
}

public function title(): string
Expand Down Expand Up @@ -223,6 +229,20 @@ public function getProcessedDescriptionForBlock(): string
* @return array
*/
public function getSettings(): array
{
$optionName = 'mollie_wc_gateway_' . $this->id . '_settings';
$settings = get_option($optionName, false);
if (!$settings) {
$settings = [];
}
return $settings;
}

/**
* Update the payment method's settings with defaults if not exist
* @return array
*/
public function updateSettingsWithDefaults(): array
{
$optionName = 'mollie_wc_gateway_' . $this->id . '_settings';
$settings = get_option($optionName, false);
Expand Down
12 changes: 10 additions & 2 deletions src/PaymentMethods/Alma.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protected function getConfig(): array
{
return [
'id' => 'alma',
'defaultTitle' => __('Alma', 'mollie-payments-for-woocommerce'),
'defaultTitle' => 'Alma',
'settingsDescription' => '',
'defaultDescription' => '',
'paymentFields' => false,
Expand All @@ -29,7 +29,15 @@ protected function getConfig(): array
'docs' => 'https://www.mollie.com/gb/payments/alma',
];
}

// Replace translatable strings after the 'after_setup_theme' hook
public function initializeTranslations(): void
{
if ($this->translationsInitialized) {
return;
}
$this->config['defaultTitle'] = __('Alma', 'mollie-payments-for-woocommerce');
$this->translationsInitialized = true;
}
public function getFormFields($generalFormFields): array
{
return $generalFormFields;
Expand Down
17 changes: 15 additions & 2 deletions src/PaymentMethods/Applepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ protected function getConfig(): array
{
return [
'id' => 'applepay',
'defaultTitle' => __('Apple Pay', 'mollie-payments-for-woocommerce'),
'settingsDescription' => __('To accept payments via Apple Pay', 'mollie-payments-for-woocommerce'),
'defaultTitle' => 'Apple Pay',
'settingsDescription' => 'To accept payments via Apple Pay',
'defaultDescription' => '',
'paymentFields' => false,
'instructions' => true,
Expand All @@ -28,6 +28,19 @@ protected function getConfig(): array
];
}

// Replace translatable strings after the 'after_setup_theme' hook
public function initializeTranslations(): void
{
if ($this->translationsInitialized) {
return;
}
$this->config['defaultTitle'] = __('Apple Pay', 'mollie-payments-for-woocommerce');
$this->config['settingsDescription'] = __(
'To accept payments via Apple Pay',
'mollie-payments-for-woocommerce'
);
$this->translationsInitialized = true;
}
public function getFormFields($generalFormFields): array
{

Expand Down
12 changes: 11 additions & 1 deletion src/PaymentMethods/Bancomatpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function getConfig(): array
{
return [
'id' => 'bancomatpay',
'defaultTitle' => __('Bancomat Pay', 'mollie-payments-for-woocommerce'),
'defaultTitle' => 'Bancomat Pay',
'settingsDescription' => '',
'defaultDescription' => '',
'paymentFields' => false,
Expand All @@ -25,6 +25,16 @@ public function getConfig(): array
];
}

// Replace translatable strings after the 'after_setup_theme' hook
public function initializeTranslations(): void
{
if ($this->translationsInitialized) {
return;
}
$this->config['defaultTitle'] = __('Bancomat Pay', 'mollie-payments-for-woocommerce');
$this->translationsInitialized = true;
}

public function getFormFields($generalFormFields): array
{
return $generalFormFields;
Expand Down
12 changes: 11 additions & 1 deletion src/PaymentMethods/Bancontact.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protected function getConfig(): array
{
return [
'id' => 'bancontact',
'defaultTitle' => __('Bancontact', 'mollie-payments-for-woocommerce'),
'defaultTitle' => 'Bancontact',
'settingsDescription' => '',
'defaultDescription' => '',
'paymentFields' => false,
Expand All @@ -26,6 +26,16 @@ protected function getConfig(): array
];
}

// Replace translatable strings after the 'after_setup_theme' hook
public function initializeTranslations(): void
{
if ($this->translationsInitialized) {
return;
}
$this->config['defaultTitle'] = __('Bancontact', 'mollie-payments-for-woocommerce');
$this->translationsInitialized = true;
}

public function getFormFields($generalFormFields): array
{
return $generalFormFields;
Expand Down
13 changes: 12 additions & 1 deletion src/PaymentMethods/Banktransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function getConfig(): array
{
return [
'id' => 'banktransfer',
'defaultTitle' => __('Bank Transfer', 'mollie-payments-for-woocommerce'),
'defaultTitle' => 'Bank Transfer',
'settingsDescription' => '',
'defaultDescription' => '',
'paymentFields' => false,
Expand All @@ -46,6 +46,17 @@ protected function getConfig(): array
];
}

// Replace translatable strings after the 'after_setup_theme' hook
public function initializeTranslations(): void
{
if ($this->translationsInitialized) {
return;
}
$this->config['defaultTitle'] = __('Bank Transfer', 'mollie-payments-for-woocommerce');
$this->translationsInitialized = true;
}


public function getFormFields($generalFormFields): array
{
unset($generalFormFields['activate_expiry_days_setting']);
Expand Down
11 changes: 10 additions & 1 deletion src/PaymentMethods/Belfius.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protected function getConfig(): array
{
return [
'id' => 'belfius',
'defaultTitle' => __('Belfius Direct Net', 'mollie-payments-for-woocommerce'),
'defaultTitle' => 'Belfius Direct Net',
'settingsDescription' => '',
'defaultDescription' => '',
'paymentFields' => false,
Expand All @@ -26,6 +26,15 @@ protected function getConfig(): array
];
}

// Replace translatable strings after the 'after_setup_theme' hook
public function initializeTranslations(): void
{
if ($this->translationsInitialized) {
return;
}
$this->config['defaultTitle'] = __('Belfius Direct Net', 'mollie-payments-for-woocommerce');
$this->translationsInitialized = true;
}
public function getFormFields($generalFormFields): array
{
return $generalFormFields;
Expand Down
37 changes: 27 additions & 10 deletions src/PaymentMethods/Billie.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ protected function getConfig(): array
{
return [
'id' => 'billie',
'defaultTitle' => __('Billie', 'mollie-payments-for-woocommerce'),
'settingsDescription' => __(
'To accept payments via Billie, all default WooCommerce checkout fields should be enabled and required.',
'mollie-payments-for-woocommerce'
),
'defaultTitle' => 'Billie',
'settingsDescription' => 'To accept payments via Billie, all default WooCommerce checkout fields should be enabled and required.',
'defaultDescription' => '',
'paymentFields' => true,
'instructions' => false,
Expand All @@ -36,15 +33,35 @@ protected function getConfig(): array
'confirmationDelayed' => false,
'SEPA' => false,
'orderMandatory' => true,
'errorMessage' => __(
'Company field is empty. The company field is required.',
'mollie-payments-for-woocommerce'
),
'companyPlaceholder' => __('Please enter your company name here.', 'mollie-payments-for-woocommerce'),
'errorMessage' => 'Company field is empty. The company field is required.',
'companyPlaceholder' => 'Please enter your company name here.',
'docs' => 'https://www.mollie.com/gb/payments/billie',
];
}

// Replace translatable strings after the 'after_setup_theme' hook
public function initializeTranslations(): void
{
if ($this->translationsInitialized) {
return;
}
$this->config['defaultTitle'] = __('Billie', 'mollie-payments-for-woocommerce');
$this->config['settingsDescription'] = __(
'To accept payments via Billie, all default WooCommerce checkout fields should be enabled and required.',
'mollie-payments-for-woocommerce'
);
$this->config['errorMessage'] = __(
'Company field is empty. The company field is required.',
'mollie-payments-for-woocommerce'
);
$this->config['companyPlaceholder'] = __(
'Please enter your company name here.',
'mollie-payments-for-woocommerce'
);

$this->translationsInitialized = true;
}

/**
* Add filters and actions for the Billie payment method.
* This will be added during constructor
Expand Down
12 changes: 11 additions & 1 deletion src/PaymentMethods/Blik.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protected function getConfig(): array
{
return [
'id' => 'blik',
'defaultTitle' => __('BLIK', 'mollie-payments-for-woocommerce'),
'defaultTitle' => 'BLIK',
'settingsDescription' => '',
'defaultDescription' => '',
'paymentFields' => false,
Expand All @@ -26,6 +26,16 @@ protected function getConfig(): array
];
}

// Replace translatable strings after the 'after_setup_theme' hook
public function initializeTranslations(): void
{
if ($this->translationsInitialized) {
return;
}
$this->config['defaultTitle'] = __('BLIK', 'mollie-payments-for-woocommerce');
$this->translationsInitialized = true;
}

public function getFormFields($generalFormFields): array
{
return $generalFormFields;
Expand Down
11 changes: 10 additions & 1 deletion src/PaymentMethods/Creditcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected function getConfig(): array
{
return [
'id' => 'creditcard',
'defaultTitle' => __('Credit card', 'mollie-payments-for-woocommerce'),
'defaultTitle' => 'Credit card',
'settingsDescription' => '',
'defaultDescription' => '',
'paymentFields' => $this->hasPaymentFields(),
Expand All @@ -31,6 +31,15 @@ protected function getConfig(): array
];
}

public function initializeTranslations(): void
{
if ($this->translationsInitialized) {
return;
}
$this->config['defaultTitle'] = __('Credit card', 'mollie-payments-for-woocommerce');
$this->translationsInitialized = true;
}

public function getFormFields($generalFormFields): array
{
$componentFields = $this->includeMollieComponentsFields($generalFormFields);
Expand Down
Loading

0 comments on commit 2e68334

Please sign in to comment.