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

Conversation

osmansufy
Copy link

@osmansufy osmansufy commented Nov 12, 2024

Summary by CodeRabbit

  • New Features

    • Introduced functionality for translating the request quote button text.
    • Added dynamic registration of button text translations upon quote rule creation or updates.
  • Enhancements

    • Improved integration of the request quote feature with WPML for better localization support.

@osmansufy osmansufy self-assigned this Nov 12, 2024
Copy link

coderabbitai bot commented Nov 12, 2024

Walkthrough

The changes in this pull request involve enhancements to the Dokan_WPML class within the dokan-wpml.php file, specifically aimed at improving the request quote feature's translation capabilities. Three new public methods are introduced for retrieving translated button text, hiding price text, and registering this text during the creation or update of quote rules. Additionally, two action hooks are added to trigger the registration method dynamically. The modifications integrate seamlessly with existing functionalities, maintaining the overall structure of the class.

Changes

File Change Summary
dokan-wpml.php - Added method get_translated_dokan_request_quote_button_text(string $text, $rule): string
- Added method get_translated_dokan_request_quote_price_hide(string $text, $rule): string
- Added method dokan_request_quote_button_text_registration(bool $action, array $args, int $rule_id)
- Introduced action hooks dokan_quote_rule_created and dokan_quote_rule_updated

Possibly related PRs

Suggested labels

Need Testing, Dev Review Done

Suggested reviewers

  • shohag121
  • MdAsifHossainNadim

Poem

In the fields where translations play,
A button's text finds its way.
With quotes that dance and rules that sing,
Localization's a joyful thing!
Hops of code, a happy cheer,
For every change, we hold so dear! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
dokan-wpml.php (1)

1340-1357: Consider adding type hints for the args parameter.

The method implementation is correct, but could benefit from more specific type hints for better code maintainability and IDE support.

-    public function dokan_request_quote_button_text_registration(bool $action, array $args, int $rule_id)
+    /**
+     * @param bool $action
+     * @param array{button_text: string} $args
+     * @param int $rule_id
+     */
+    public function dokan_request_quote_button_text_registration(bool $action, array $args, int $rule_id): void
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9ecb21d and 79187f8.

📒 Files selected for processing (1)
  • dokan-wpml.php (2 hunks)
🔇 Additional comments (3)
dokan-wpml.php (3)

169-171: LGTM: Action hooks are properly implemented.

The hooks for quote rule creation and update are correctly implemented and follow WordPress conventions.


173-175: LGTM: Filter is properly implemented.

The filter for request quote button text translation is correctly implemented and consistently placed with other translation filters.


1327-1339: LGTM: Translation getter method is well implemented.

The method properly handles translation retrieval using the existing infrastructure and includes appropriate type hints.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
dokan-wpml.php (2)

1329-1341: Clarify the type of the $rule parameter in the docblock

To enhance code understanding and static analysis, specify the exact class or interface of the $rule parameter in the docblock for get_translated_dokan_request_quote_button_text.

Apply this diff to update the docblock:

 /**
  * 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.
+ * @param \Dokan_Rule $rule The rule object containing the ID.
  *
  * @return string The translated button text.
  */

Replace \Dokan_Rule with the actual class name of the $rule object.


1343-1346: Add a docblock for get_translated_dokan_request_quote_price_hide method

The method get_translated_dokan_request_quote_price_hide lacks a docblock. Adding one will improve code readability and maintainability.

Consider adding the following docblock:

/**
 * Get the translated text for hiding the price in the Dokan request quote.
 *
 * @param string $text The original hide price text.
 * @param \Dokan_Rule $rule The rule object containing the ID.
 *
 * @return string The translated hide price text.
 */

Ensure that \Dokan_Rule is replaced with the correct class name of the $rule object.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 79187f8 and 4d65353.

📒 Files selected for processing (1)
  • dokan-wpml.php (2 hunks)
🔇 Additional comments (1)
dokan-wpml.php (1)

169-178: Verify that action hook parameters match the method signature

The method dokan_request_quote_button_text_registration is hooked to dokan_quote_rule_created and dokan_quote_rule_updated with 3 parameters. Ensure that these actions pass parameters matching the method's signature (bool $action, array $args, int $rule_id) to prevent potential errors.

Run the following script to verify the action hook parameters:

dokan-wpml.php Outdated
Comment on lines 1348 to 1369
/**
* 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 );
}

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4d65353 and 7d4ab46.

📒 Files selected for processing (1)
  • dokan-wpml.php (2 hunks)
🔇 Additional comments (1)
dokan-wpml.php (1)

1357-1369: Confirmed: Handling of undefined array keys is now safe

The use of the null coalescing operator ensures that 'button_text' and 'hide_price_text' are retrieved safely from $args, preventing undefined index notices if these keys are missing.

Comment on lines +1338 to +1341
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 );
}
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 );
}

Comment on lines +1343 to +1346
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 );
}
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 );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant