-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThis 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
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
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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
# Conflicts: # dokan-wpml.php
There was a problem hiding this 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
📒 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.
/** | ||
* 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 ); | ||
} |
There was a problem hiding this comment.
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:
- Added parameter type hints for better type safety
- Added void return type to register_shipping_method_title()
- Fixed spacing in method parameters
- 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.
/** | |
* 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 ); | |
} |
|
||
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 ); | ||
} |
There was a problem hiding this comment.
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.
Summary by CodeRabbit
Related PR: https://github.com/getdokan/dokan-pro/pull/4209