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

update: shipping method title translate support #96

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

osmansufy
Copy link

@osmansufy osmansufy commented Feb 6, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced multilingual support for shipping methods with automated translation for shipping titles.
    • Introduced mechanisms to register and retrieve localized shipping method titles, improving integration with multilingual setups.
    • Added action and filter hooks to facilitate the registration and retrieval of translated shipping method titles.

Related PR: https://github.com/getdokan/dokan-pro/pull/4209

Copy link

coderabbitai bot commented Feb 6, 2025

Walkthrough

This pull request introduces new functionality to the Dokan WPML module by adding two public methods to handle shipping method title translations. The first method registers a shipping method title, while the second retrieves its translated version. Both methods use existing helper functions for string registration and translation. An action hook is also added to trigger the registration process during shipping method title updates.

Changes

File Change Summary
dokan-wpml.php Added register_shipping_method_title() and get_translated_shipping_method_title() methods; introduced the dokan_shipping_method_title_update action hook.

Sequence Diagram(s)

sequenceDiagram
    participant S as Shipping Process
    participant D as Dokan_WPML
    participant TS as Translation System

    S->>D: Trigger dokan_shipping_method_title_update
    D->>TS: register_single_string(title, instance_id)
    S->>D: Request translated title via get_translated_shipping_method_title
    D->>TS: get_translated_single_string(title, instance_id)
    TS-->>D: Return translated title
Loading

Possibly related PRs

Suggested labels

Need Testing, Dev Review Done

Suggested reviewers

  • shohag121
  • MdAsifHossainNadim

Poem

I'm a rabbit in a code field, hopping light,
New shipping titles make my day so bright.
Methods added, hooks in play,
Translating strings without delay.
With every line, I leap with cheer—
Code changes, my favorite frontier!
Hop on, the future is clear!


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@osmansufy osmansufy requested a review from mrabbani February 6, 2025 10:06
@osmansufy osmansufy self-assigned this Feb 6, 2025
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

🧹 Nitpick comments (2)
dokan-wpml.php (2)

1299-1312: Add type hints and parameter validation.

The method should include:

  • Parameter type hints for better type safety
  • Parameter validation to ensure valid input
  • Return type hint for consistency

Apply this diff to improve the method:

-    public function register_shipping_method_title( $title,$instance_id ){
+    public function register_shipping_method_title( string $title, int $instance_id ): void {
+        if ( empty( $title ) || $instance_id <= 0 ) {
+            return;
+        }
+
         $this->register_single_string( 'dokan', 'Dokan Shipping Method Title: ' . $instance_id, $title );
     }

1314-1327: Add parameter type hints and validation.

The method should include:

  • Parameter type hints for better type safety
  • Parameter validation to ensure valid input

Apply this diff to improve the method:

-    public function get_translated_shipping_method_title ( $title,$instance_id ): string {
+    public function get_translated_shipping_method_title( string $title, int $instance_id ): string {
+        if ( empty( $title ) || $instance_id <= 0 ) {
+            return $title;
+        }
+
         return $this->get_translated_single_string( $title, 'dokan', 'Dokan Shipping Method Title: ' . $instance_id );
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

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

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

172-176: LGTM! Hook registration follows WordPress conventions.

The hooks are properly registered to handle shipping method title translations:

  • Action hook to register titles when they are updated
  • Filter hook to retrieve translated titles when needed

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f64385a and d3d4ccf.

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

176-179: LGTM! Well-structured hook declarations.

The new hooks follow WordPress naming conventions and are properly placed in the plugins_loaded method.

Comment on lines +1408 to +1436
/**
* Register shipping method title for string translation.
*
* @since 1.1.6
*
* @param string $title Shipping Method Title.
* @param int $instance_id Shipping Method Instance ID.
*
* @return void
*/

public function register_shipping_method_title( $title,$instance_id ){
$this->register_single_string( 'dokan', 'Dokan Shipping Method Title: ' . $instance_id, $title );
}

/**
* Get translated shipping method title.
*
* @since 1.1.6
*
* @param string $title Shipping Method Title.
* @param int $instance_id Shipping Method Instance ID.
*
* @return string
*/

public function get_translated_shipping_method_title ( $title,$instance_id ): string {
return $this->get_translated_single_string( $title, 'dokan', 'Dokan Shipping Method Title: ' . $instance_id );
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve method consistency and type safety.

The new methods need improvements for better consistency and type safety:

Apply these changes:

-    public function register_shipping_method_title( $title,$instance_id ){
+    public function register_shipping_method_title( string $title, int $instance_id ): void {
         $this->register_single_string( 'dokan', 'Dokan Shipping Method Title: ' . $instance_id, $title );
     }

-    public function get_translated_shipping_method_title ( $title,$instance_id ): string {
+    public function get_translated_shipping_method_title( string $title, int $instance_id ): string {
         return $this->get_translated_single_string( $title, 'dokan', 'Dokan Shipping Method Title: ' . $instance_id );
     }

Changes:

  1. Added parameter type hints for better type safety
  2. Added void return type to register_shipping_method_title()
  3. Fixed spacing in method parameters
  4. Fixed spacing in method name
📝 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
/**
* Register shipping method title for string translation.
*
* @since 1.1.6
*
* @param string $title Shipping Method Title.
* @param int $instance_id Shipping Method Instance ID.
*
* @return void
*/
public function register_shipping_method_title( $title,$instance_id ){
$this->register_single_string( 'dokan', 'Dokan Shipping Method Title: ' . $instance_id, $title );
}
/**
* Get translated shipping method title.
*
* @since 1.1.6
*
* @param string $title Shipping Method Title.
* @param int $instance_id Shipping Method Instance ID.
*
* @return string
*/
public function get_translated_shipping_method_title ( $title,$instance_id ): string {
return $this->get_translated_single_string( $title, 'dokan', 'Dokan Shipping Method Title: ' . $instance_id );
}
/**
* Register shipping method title for string translation.
*
* @since 1.1.6
*
* @param string $title Shipping Method Title.
* @param int $instance_id Shipping Method Instance ID.
*
* @return void
*/
public function register_shipping_method_title( string $title, int $instance_id ): void {
$this->register_single_string( 'dokan', 'Dokan Shipping Method Title: ' . $instance_id, $title );
}
/**
* Get translated shipping method title.
*
* @since 1.1.6
*
* @param string $title Shipping Method Title.
* @param int $instance_id Shipping Method Instance ID.
*
* @return string
*/
public function get_translated_shipping_method_title( string $title, int $instance_id ): string {
return $this->get_translated_single_string( $title, 'dokan', 'Dokan Shipping Method Title: ' . $instance_id );
}

Comment on lines +1418 to +1436

public function register_shipping_method_title( $title,$instance_id ){
$this->register_single_string( 'dokan', 'Dokan Shipping Method Title: ' . $instance_id, $title );
}

/**
* Get translated shipping method title.
*
* @since 1.1.6
*
* @param string $title Shipping Method Title.
* @param int $instance_id Shipping Method Instance ID.
*
* @return string
*/

public function get_translated_shipping_method_title ( $title,$instance_id ): string {
return $this->get_translated_single_string( $title, 'dokan', 'Dokan Shipping Method Title: ' . $instance_id );
}
Copy link
Member

Choose a reason for hiding this comment

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

Please fix phpcs issues and add type casting.

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