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

FIx/Few string does not translate regarding the Dokan RFQ module. #220 #88

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions dokan-wpml.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ public function plugins_loaded() {
add_action( 'dokan_disable_url_translation', [ $this, 'disable_url_translation' ] );
add_action( 'dokan_enable_url_translation', [ $this, 'enable_url_translation' ] );

// Request rule create/update hooks
add_action( 'dokan_quote_rule_created', [$this, 'dokan_request_quote_button_text_registration'], 10, 3 );
add_action( 'dokan_quote_rule_updated', [$this, 'dokan_request_quote_button_text_registration'], 10, 3 );

// Request quote button text filter

add_filter( 'dokan_request_quote_button_text', [$this, 'get_translated_dokan_request_quote_button_text'], 10, 2 );

// Request quote price hide filter
add_filter( 'dokan_request_quote_price_hide', [$this, 'get_translated_dokan_request_quote_price_hide'], 10, 2 );
add_filter( 'wp', [ $this, 'set_translated_query_var_to_default_query_var' ], 11 );
add_filter( 'dokan_set_store_categories', [ $this, 'set_translated_category' ] );
add_filter( 'dokan_get_store_categories_in_vendor', [ $this, 'get_translated_category' ] );
Expand Down Expand Up @@ -1316,6 +1326,47 @@ public function get_translated_verification_method_title( $title ) {
public function get_translated_verification_method_help_text( $help_text ) {
return $this->get_translated_single_string( $help_text, 'dokan', 'Dokan Vendor Verification Method Help Text: ' . substr( $help_text, 0, 116 ) );
}

/**
* Get the translated text for the Dokan request quote button.
*
* @param string $text The original button text.
* @param object $rule The rule object containing the ID.
*
* @return string The translated button text.
*/
public function get_translated_dokan_request_quote_button_text(string $text, $rule): string
{
return $this->get_translated_single_string( $text, 'dokan', 'Dokan Request Quote Button Text: ' . $rule->id );
}
Comment on lines +1338 to +1341
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null checks for $rule to prevent potential errors

In the method get_translated_dokan_request_quote_button_text, you're accessing $rule->id without verifying that $rule is an object and that the id property exists. This could lead to errors if $rule is null or doesn't have an id.

Apply this diff to add checks before accessing $rule->id:

 public function get_translated_dokan_request_quote_button_text(string $text, $rule): string
 {
+    if ( ! is_object( $rule ) || ! isset( $rule->id ) ) {
+        return $text;
+    }
     return $this->get_translated_single_string( $text, 'dokan', 'Dokan Request Quote Button Text: ' . $rule->id );
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public function get_translated_dokan_request_quote_button_text(string $text, $rule): string
{
return $this->get_translated_single_string( $text, 'dokan', 'Dokan Request Quote Button Text: ' . $rule->id );
}
public function get_translated_dokan_request_quote_button_text(string $text, $rule): string
{
if ( ! is_object( $rule ) || ! isset( $rule->id ) ) {
return $text;
}
return $this->get_translated_single_string( $text, 'dokan', 'Dokan Request Quote Button Text: ' . $rule->id );
}


public function get_translated_dokan_request_quote_price_hide(string $text, $rule): string
{
return $this->get_translated_single_string( $text, 'dokan', 'Dokan Request Quote Hide Price Text: ' . $rule->id );
}
Comment on lines +1343 to +1346
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null checks for $rule to prevent potential errors

In the method get_translated_dokan_request_quote_price_hide, you're accessing $rule->id without verifying that $rule is an object and that the id property exists. This may cause errors if $rule is null or lacks the id property.

Apply this diff to add checks before accessing $rule->id:

 public function get_translated_dokan_request_quote_price_hide(string $text, $rule): string
 {
+    if ( ! is_object( $rule ) || ! isset( $rule->id ) ) {
+        return $text;
+    }
     return $this->get_translated_single_string( $text, 'dokan', 'Dokan Request Quote Hide Price Text: ' . $rule->id );
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public function get_translated_dokan_request_quote_price_hide(string $text, $rule): string
{
return $this->get_translated_single_string( $text, 'dokan', 'Dokan Request Quote Hide Price Text: ' . $rule->id );
}
public function get_translated_dokan_request_quote_price_hide(string $text, $rule): string
{
if ( ! is_object( $rule ) || ! isset( $rule->id ) ) {
return $text;
}
return $this->get_translated_single_string( $text, 'dokan', 'Dokan Request Quote Hide Price Text: ' . $rule->id );
}


/**
* Registers the request quote button text for translation.
*
* @param bool $action The action status.
* @param array $args The arguments containing the button text.
* @param int $rule_id The ID of the rule.
*
* @return void
*/
public function dokan_request_quote_button_text_registration(bool $action, array $args, int $rule_id)
{
if (! $action) {
return;
}
$button_text = $args['button_text'];
$this->register_single_string( 'dokan', 'Dokan Request Quote Button Text: ' . $rule_id, $button_text );

$hide_price_text = $args['hide_price_text'];

$this->register_single_string( 'dokan', 'Dokan Request Quote Hide Price Text: ' . $rule_id, $hide_price_text );

}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Prevent undefined index errors by checking array keys

In the method dokan_request_quote_button_text_registration, the keys 'button_text' and 'hide_price_text' are accessed directly from $args without checking if they exist. This could lead to undefined index notices if these keys are missing.

Apply this diff to add checks for the array keys:

 public function dokan_request_quote_button_text_registration(bool $action, array $args, int $rule_id)
 {
     if (! $action) {
         return;
     }
-    $button_text = $args['button_text'];
+    $button_text = isset( $args['button_text'] ) ? $args['button_text'] : '';

     $this->register_single_string( 'dokan', 'Dokan Request Quote Button Text: ' . $rule_id, $button_text );

-    $hide_price_text = $args['hide_price_text'];
+    $hide_price_text = isset( $args['hide_price_text'] ) ? $args['hide_price_text'] : '';

     $this->register_single_string( 'dokan', 'Dokan Request Quote Hide Price Text: ' . $rule_id, $hide_price_text );
 }

Alternatively, if you're using PHP 7 or higher, you can use the null coalescing operator:

-    $button_text = $args['button_text'];
+    $button_text = $args['button_text'] ?? '';

...

-    $hide_price_text = $args['hide_price_text'];
+    $hide_price_text = $args['hide_price_text'] ?? '';

Ensure that using a default value aligns with the desired behavior of your application.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Registers the request quote button text for translation.
*
* @param bool $action The action status.
* @param array $args The arguments containing the button text.
* @param int $rule_id The ID of the rule.
*
* @return void
*/
public function dokan_request_quote_button_text_registration(bool $action, array $args, int $rule_id)
{
if (! $action) {
return;
}
$button_text = $args['button_text'];
$this->register_single_string( 'dokan', 'Dokan Request Quote Button Text: ' . $rule_id, $button_text );
$hide_price_text = $args['hide_price_text'];
$this->register_single_string( 'dokan', 'Dokan Request Quote Hide Price Text: ' . $rule_id, $hide_price_text );
}
/**
* Registers the request quote button text for translation.
*
* @param bool $action The action status.
* @param array $args The arguments containing the button text.
* @param int $rule_id The ID of the rule.
*
* @return void
*/
public function dokan_request_quote_button_text_registration(bool $action, array $args, int $rule_id)
{
if (! $action) {
return;
}
$button_text = isset( $args['button_text'] ) ? $args['button_text'] : '';
$this->register_single_string( 'dokan', 'Dokan Request Quote Button Text: ' . $rule_id, $button_text );
$hide_price_text = isset( $args['hide_price_text'] ) ? $args['hide_price_text'] : '';
$this->register_single_string( 'dokan', 'Dokan Request Quote Hide Price Text: ' . $rule_id, $hide_price_text );
}

} // Dokan_WPML

function dokan_load_wpml() { // phpcs:ignore
Expand Down