Skip to content

Commit 30a292c

Browse files
refactor: use a dedicate function for default translatable labels
1 parent 039775d commit 30a292c

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

inc/API.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public function register_routes() {
234234
* @return \WP_REST_Response
235235
*/
236236
public function get_settings() {
237+
Main::add_labels_to_default_settings();
237238
$settings = Main::get_settings();
238239
return rest_ensure_response( $settings );
239240
}
@@ -694,11 +695,10 @@ function ( $message ) use ( $run_id ) {
694695
return rest_ensure_response( [ 'error' => __( 'No messages found.', 'hyve-lite' ) ] );
695696
}
696697

698+
Main::add_labels_to_default_settings();
697699
$settings = Main::get_settings();
698700

699-
$default_message = isset( $settings['default_message'] ) ? $settings['default_message'] : __( 'Sorry, I\'m not able to help with that.', 'hyve-lite' );
700-
701-
$response = ( isset( $message['success'] ) && true === $message['success'] && isset( $message['response'] ) ) ? $message['response'] : esc_html( $default_message );
701+
$response = ( isset( $message['success'] ) && true === $message['success'] && isset( $message['response'] ) ) ? $message['response'] : esc_html( $settings['default_message'] );
702702

703703
do_action( 'hyve_chat_response', $run_id, $thread_id, $query, $record_id, $message, $response );
704704

inc/Main.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ public static function get_default_settings() {
205205
'harassment/threatening' => 60,
206206
'violence' => 70,
207207
],
208+
'welcome_message' => '',
209+
'default_message' => '',
208210
]
209211
);
210212
}
@@ -221,6 +223,31 @@ public static function get_settings() {
221223
return wp_parse_args( $settings, self::get_default_settings() );
222224
}
223225

226+
/**
227+
* Add the translatable label to the default value.
228+
*
229+
* Use this in a context where translations are correctly loaded.
230+
*
231+
* @since 1.2
232+
*
233+
* @return void
234+
*/
235+
public static function add_labels_to_default_settings() {
236+
add_filter(
237+
'hyve_default_settings',
238+
function ( $settings ) {
239+
if ( ! is_array( $settings ) ) {
240+
return $settings;
241+
}
242+
243+
$settings['welcome_message'] = __( 'Hello! How can I help you today?', 'hyve-lite' );
244+
$settings['default_message'] = __( 'Sorry, I\'m not able to help with that.', 'hyve-lite' );
245+
246+
return $settings;
247+
}
248+
);
249+
}
250+
224251
/**
225252
* Enqueue assets.
226253
*
@@ -252,6 +279,7 @@ public function enqueue_assets() {
252279

253280
wp_set_script_translations( 'hyve-lite-scripts', 'hyve-lite' );
254281

282+
self::add_labels_to_default_settings();
255283
$settings = self::get_settings();
256284

257285
wp_localize_script(
@@ -265,7 +293,7 @@ public function enqueue_assets() {
265293
'click' => HYVE_LITE_URL . 'assets/audio/click.mp3',
266294
'ping' => HYVE_LITE_URL . 'assets/audio/ping.mp3',
267295
],
268-
'welcome' => esc_html( $settings['welcome_message'] ?? __( 'Hello! How can I help you today?', 'hyve-lite' ) ),
296+
'welcome' => esc_html( $settings['welcome_message'] ?? '' ),
269297
'isEnabled' => $settings['chat_enabled'],
270298
'strings' => [
271299
'reply' => __( 'Write a reply…', 'hyve-lite' ),

src/backend/parts/ModerationReview.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const ModerationReview = ({
5757
return (
5858
<Modal
5959
title={ sprintf(
60+
6061
// translators: %s the reason for failed moderation.
6162
__( 'Failed Moderation: %s', 'hyve-lite' ), ( post?.title || __( 'Untitled', 'hyve-lite' ) ) ) }
6263
onRequestClose={ onClose }

0 commit comments

Comments
 (0)