Skip to content

Commit 50a99b3

Browse files
fix: translation errors (#67)
Fix errors and warnings related to translations (move the translation function call to a context where translation is available)
1 parent 9001f17 commit 50a99b3

5 files changed

Lines changed: 52 additions & 27 deletions

File tree

inc/API.php

Lines changed: 2 additions & 0 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,6 +695,7 @@ 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

699701
$response = ( isset( $message['success'] ) && true === $message['success'] && isset( $message['response'] ) ) ? $message['response'] : esc_html( $settings['default_message'] );

inc/BaseAPI.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,11 @@ class BaseAPI {
3636
*/
3737
protected $table;
3838

39-
/**
40-
* Error messages.
41-
*
42-
* @var array
43-
*/
44-
private $errors = [];
45-
4639
/**
4740
* Constructor.
4841
*/
4942
public function __construct() {
5043
$this->table = DB_Table::instance();
51-
52-
$this->errors = [
53-
'invalid_api_key' => __( 'Incorrect API key provided.', 'hyve-lite' ),
54-
'missing_scope' => __( ' You have insufficient permissions for this operation.', 'hyve-lite' ),
55-
];
5644
}
5745

5846
/**
@@ -63,8 +51,12 @@ public function __construct() {
6351
* @return string
6452
*/
6553
public function get_error_message( $error ) {
66-
if ( isset( $this->errors[ $error->get_error_code() ] ) ) {
67-
return $this->errors[ $error->get_error_code() ];
54+
$errors = [
55+
'invalid_api_key' => __( 'Incorrect API key provided.', 'hyve-lite' ),
56+
'missing_scope' => __( 'You have insufficient permissions for this operation.', 'hyve-lite' ),
57+
];
58+
if ( isset( $errors[ $error->get_error_code() ] ) ) {
59+
return $errors[ $error->get_error_code() ];
6860
}
6961

7062
return $error->get_error_message();

inc/Main.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ public static function get_default_settings() {
189189
'qdrant_api_key' => '',
190190
'qdrant_endpoint' => '',
191191
'chat_enabled' => true,
192-
'welcome_message' => __( 'Hello! How can I help you today?', 'hyve-lite' ),
193-
'default_message' => __( 'Sorry, I\'m not able to help with that.', 'hyve-lite' ),
194192
'chat_model' => 'gpt-4o-mini',
195193
'temperature' => 1,
196194
'top_p' => 1,
@@ -207,6 +205,8 @@ public static function get_default_settings() {
207205
'harassment/threatening' => 60,
208206
'violence' => 70,
209207
],
208+
'welcome_message' => '',
209+
'default_message' => '',
210210
]
211211
);
212212
}
@@ -223,6 +223,31 @@ public static function get_settings() {
223223
return wp_parse_args( $settings, self::get_default_settings() );
224224
}
225225

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+
226251
/**
227252
* Enqueue assets.
228253
*
@@ -254,6 +279,7 @@ public function enqueue_assets() {
254279

255280
wp_set_script_translations( 'hyve-lite-scripts', 'hyve-lite' );
256281

282+
self::add_labels_to_default_settings();
257283
$settings = self::get_settings();
258284

259285
wp_localize_script(

phpcs.xml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,38 @@
22
<ruleset name="">
33
<description>ThemeIsle ruleset</description>
44

5-
<config name="testVersion" value="8.1-"/>
5+
<config name="testVersion" value="8.1-" />
66

77
<rule ref="WordPress-VIP-Go" />
88

99
<rule ref="WordPress-Core">
10-
<exclude name="WordPress.DB.SlowDBQuery.slow_db_query_meta_query"/>
11-
<exclude name="WordPress.DB.DirectDatabaseQuery.NoCaching"/>
12-
<exclude name="WordPress.DB.DirectDatabaseQuery.DirectQuery"/>
10+
<exclude name="WordPress.DB.SlowDBQuery.slow_db_query_meta_query" />
11+
<exclude name="WordPress.DB.DirectDatabaseQuery.NoCaching" />
12+
<exclude name="WordPress.DB.DirectDatabaseQuery.DirectQuery" />
1313
</rule>
1414

1515
<rule ref="WordPress-Docs" />
1616

1717
<rule ref="WordPress-Extra">
1818
<!-- Forget about file names -->
19-
<exclude name="WordPress.Files.FileName"/>
20-
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found"/>
19+
<exclude name="WordPress.Files.FileName" />
20+
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found" />
2121
</rule>
2222

2323
<rule ref="PHPCompatibility" />
2424

2525
<rule ref="WordPress.WP.I18n">
2626
<properties>
27-
<property name="text_domain" value="quickwp" />
27+
<property name="text_domain" type="array">
28+
<element value="hyve-lite" />
29+
</property>
2830
</properties>
2931
</rule>
3032

31-
<rule ref="Generic.Arrays.DisallowLongArraySyntax.Found"/>
33+
<rule ref="Generic.Arrays.DisallowLongArraySyntax.Found" />
3234

33-
<arg name="extensions" value="php"/>
34-
<arg value="s"/>
35+
<arg name="extensions" value="php" />
36+
<arg value="s" />
3537

3638
<file>.</file>
3739
<exclude-pattern>node_modules/*</exclude-pattern>

src/backend/parts/ModerationReview.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ const ModerationReview = ({
5656

5757
return (
5858
<Modal
59-
title={ sprintf( __( 'Failed Moderation: %s', 'hyve-lite' ), ( post?.title || __( 'Untitled', 'hyve-lite' ) ) ) }
59+
title={ sprintf(
60+
61+
// translators: %s the reason for failed moderation.
62+
__( 'Failed Moderation: %s', 'hyve-lite' ), ( post?.title || __( 'Untitled', 'hyve-lite' ) ) ) }
6063
onRequestClose={ onClose }
6164
shouldCloseOnClickOutside={ false }
6265
className="md:max-w-3xl md:w-full"

0 commit comments

Comments
 (0)