Skip to content

Commit 00fa96b

Browse files
committed
Fix localization errors and add phpcs sniffer to prevent misconfigured localization
1 parent f86f4af commit 00fa96b

File tree

7 files changed

+23
-79
lines changed

7 files changed

+23
-79
lines changed

assets/src/dashboard/parts/connected/dashboard/index.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,7 @@ const Dashboard = () => {
172172
const visitorsLimitPercent = ( ( userData.visitors / userData.visitors_limit ) * 100 ).toFixed( 0 );
173173

174174
const renewalDate = useMemo( () => {
175-
const timestamp = userData.renews_on;
176-
177-
if ( ! timestamp ) {
178-
return 'N/A';
179-
}
180-
181-
const date = new Date( timestamp * 1000 );
182-
return date.toLocaleDateString( undefined, { year: 'numeric', month: 'short', day: 'numeric' });
175+
return userData.renews_on_formatted;
183176
}, [ userData.renews_on ]);
184177

185178
const formatMetric = ( type, value ) => {

assets/src/dashboard/parts/connected/settings/FilterControl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ const FilterControl = ({
275275
) : (
276276
<TextControl
277277
value={ filterValue }
278-
placeholder={ 'matches' === filterMatchType ? 'path' : 'word' }
278+
placeholder={ 'matches' === filterMatchType ? optimoleDashboardApp.strings.path : optimoleDashboardApp.strings.word }
279279
onChange={ updateFilterValue }
280280
className="optml__input"
281281
/>

assets/src/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ export interface UserData {
577577
is_cname_assigned: string
578578
extra_visits: boolean
579579
renews_on: number
580+
renews_on_formatted: string
580581
can_use_offloading: boolean
581582
domain_dns: string
582583
}

inc/admin.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,10 @@ private function localize_dashboard_app() {
13921392
if ( ! empty( $service_data ) ) {
13931393
$service_data['domain_dns'] = $this->settings->get_cdn_url();
13941394
}
1395+
if ( isset( $service_data['renews_on'] ) ) {
1396+
$service_data['renews_on_formatted'] = date_i18n( get_option( 'date_format' ), $service_data['renews_on'] );
1397+
1398+
}
13951399
return [
13961400
'strings' => $this->get_dashboard_strings(),
13971401
'assets_url' => OPTML_URL . 'assets/',
@@ -1569,7 +1573,7 @@ public function get_bf_notices() {
15691573
/* translators: number of days left */
15701574
'urgency' => sprintf( __( 'Hurry up! only %s left', 'optimole-wp' ), human_time_diff( $end, $now ) ),
15711575
/* translators: private sale */
1572-
'title' => sprintf( __( 'Black Friday %s', 'optimole-wp' ), '<span class="text-promo-orange">' . __( 'private sale' ) . '</span>' ),
1576+
'title' => sprintf( __( 'Black Friday %s', 'optimole-wp' ), '<span class="text-promo-orange">' . __( 'private sale', 'optimole-wp' ) . '</span>' ),
15731577
'subtitle' => sprintf(
15741578
/* translators: 1 is the promo code, 2 is the discount amount ('25 off') */
15751579
__( 'Use coupon code %1$s for an instant %2$s on Optimole yearly plans', 'optimole-wp' ),
@@ -1601,7 +1605,7 @@ private function get_dashboard_strings() {
16011605
'dashboard_title' => __( 'Image Optimization Overview', 'optimole-wp' ),
16021606
'banner_title' => __( 'All images are automatically optimized!', 'optimole-wp' ),
16031607
'banner_description' => __( 'Optimole is handling all your images in real-time with our CloudFront CDN (450+ locations worldwide)', 'optimole-wp' ),
1604-
'quick_action_title' => __( 'Quick Actions' ),
1608+
'quick_action_title' => __( 'Quick Actions', 'optimole-wp' ),
16051609
'connect_btn' => __( 'Connect to Optimole', 'optimole-wp' ),
16061610
'disconnect_btn' => __( 'Disconnect', 'optimole-wp' ),
16071611
'select' => __( 'Select', 'optimole-wp' ),
@@ -1621,6 +1625,8 @@ private function get_dashboard_strings() {
16211625
'keep_connected' => __( 'Ok, keep me connected', 'optimole-wp' ),
16221626
'cloud_library' => __( 'Cloud Library', 'optimole-wp' ),
16231627
'image_storage' => __( 'Image Storage', 'optimole-wp' ),
1628+
'word' => __( 'word', 'optimole-wp' ),
1629+
'path' => __( 'path', 'optimole-wp' ),
16241630
'disconnect_title' => __( 'You are about to disconnect from the Optimole API', 'optimole-wp' ),
16251631
'disconnect_desc' => __(
16261632
'Please note that disconnecting your site from the Optimole API will impact your website performance.
@@ -2265,9 +2271,9 @@ private function get_dashboard_strings() {
22652271
'contact_support' => [
22662272
// translators: %s is the email main subject.
22672273
'title_prefix' => __( '[Lazy Load Issue] %s', 'optimole-wp' ),
2268-
'disable_lazy_load_scaling' => __( 'Disable Lazy Load & Scaling' ),
2269-
'disable_image_scaling' => __( 'Disable Image Scaling' ),
2270-
'enable_native_lazy_load' => __( 'Enable Native Lazy Load' ),
2274+
'disable_lazy_load_scaling' => __( 'Disable Lazy Load & Scaling', 'optimole-wp' ),
2275+
'disable_image_scaling' => __( 'Disable Image Scaling', 'optimole-wp' ),
2276+
'enable_native_lazy_load' => __( 'Enable Native Lazy Load', 'optimole-wp' ),
22712277
],
22722278
// translators: %s is the date of the renewal.
22732279
'renew_date' => __( 'Renews %s', 'optimole-wp' ),

inc/dashboard_widget.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function add_dashboard_widget() {
3535
return;
3636
}
3737

38-
wp_add_dashboard_widget( $this->handle, sprintf( 'Optimole - %s', __( 'Image Optimization Stats', 'optimole' ) ), [ $this, 'render_widget' ] );
38+
wp_add_dashboard_widget( $this->handle, sprintf( 'Optimole - %s', __( 'Image Optimization Stats', 'optimole-wp' ) ), [ $this, 'render_widget' ] );
3939
}
4040

4141
/**

inc/rest.php

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class Optml_Rest {
4343
'service_routes' => [
4444
'update_option' => 'POST',
4545
'request_update' => 'GET',
46-
'check_redirects' => 'POST_PUT_PATCH',
4746
'connect' => [
4847
'POST',
4948
'args' => [
@@ -814,69 +813,6 @@ public function update_option( WP_REST_Request $request ) {
814813
return $this->response( $sanitized );
815814
}
816815

817-
/**
818-
* Update options method.
819-
*
820-
* @param WP_REST_Request $request option update rest request.
821-
* @phpstan-param WP_REST_Request<array{images?: array<string, array{src?: list<string>, ignoredUrls?: int}>}> $request
822-
*
823-
* @return WP_REST_Response
824-
*/
825-
public function check_redirects( WP_REST_Request $request ) {
826-
if ( empty( $request->get_param( 'images' ) ) ) {
827-
return $this->response( __( 'No images available on the current page.' ), 'noImagesFound' );
828-
}
829-
// 'ok' if no issues found, 'log' is there are issues we need to notify, 'deactivated' if the user's account is disabled
830-
$status = 'ok';
831-
$result = '';
832-
foreach ( $request->get_param( 'images' ) as $domain => $value ) {
833-
$args = [
834-
'method' => 'GET',
835-
'redirection' => 0,
836-
];
837-
$processed_images = 0;
838-
if ( isset( $value['src'] ) ) {
839-
$processed_images = count( $value['src'] );
840-
}
841-
if ( isset( $value['ignoredUrls'] ) && $value['ignoredUrls'] > $processed_images ) {
842-
$result .= '<li>❌ ' . sprintf( /* translators: 1 is the domain name, 2 is starting anchor tag, 3 is the ending anchor tag. */__( 'The images from: %1$s are not optimized by Optimole. If you would like to do so, you can follow this: %2$sWhy Optimole does not optimize all the images from my site?%3$s.', 'optimole-wp' ), $domain, '<a target="_blank" href="https://docs.optimole.com/article/1290-how-to-optimize-images-using-optimole-from-my-domain">', '</a>' ) . '</li>';
843-
$status = 'log';
844-
continue;
845-
}
846-
847-
if ( $processed_images > 0 ) {
848-
$response = wp_remote_get( $value['src'][ rand( 0, $processed_images - 1 ) ], $args );
849-
if ( ! is_wp_error( $response ) ) {
850-
$headers = $response['headers']; // array of http header lines
851-
$status_code = $response['response']['code'];
852-
if ( $status_code === 301 ) {
853-
$status = 'deactivated';
854-
$result = '<li>❌ ' . sprintf( /* translators: 1 is starting anchor tag, 2 is the ending anchor tag. */ __( 'Your account is currently disabled due to exceeding quota and Optimole is no longer able to optimize the images. In order to fix this you will need to %1$supgrade%2$s.', 'optimole-wp' ), '<a target="_blank" href="' . esc_url( tsdk_translate_link( Optml_Admin::get_upgrade_base_link() ) ) . '">', '</a>' ) . '</li>';
855-
break;
856-
}
857-
if ( $status_code === 302 ) {
858-
if ( isset( $headers['x-redirect-o'] ) ) {
859-
$optimole_code = (int) $headers['x-redirect-o'];
860-
if ( $optimole_code === 1 ) {
861-
$status = 'log';
862-
$result .= '<li>❌ ' . sprintf( /* translators: 1 is the domain, 2 is starting anchor tag, 3 is the ending anchor tag. */ __( 'The domain: %1$s is not allowed to optimize images using your Optimole account. You can add this to the allowed list %2$shere%3$s.', 'optimole-wp' ), '<b>' . $domain . '</b>', '<a target="_blank" href="' . esc_url( tsdk_translate_link( 'https://dashboard.optimole.com/whitelist', 'query' ) ) . '">', '</a>' ) . '</li>';
863-
}
864-
if ( $optimole_code === 4 ) {
865-
$status = 'log';
866-
$result .= '<li>❌ ' . sprintf( /* translators: 1 is the domain, 2 is starting anchor tag, 3 is the ending anchor tag. */ __( 'We are not able to download the images from %1$s. Please check %2$sthis%3$s document for a more advanced guide on how to solve this.', 'optimole-wp' ), '<b>' . $domain . '</b>', '<a target="_blank" href="https://docs.optimole.com/article/1291-why-optimole-is-not-able-to-download-the-images-from-my-site">', '</a>' ) . '<br />' . '</li>';
867-
}
868-
}
869-
}
870-
}
871-
}
872-
}
873-
if ( $result === '' ) {
874-
$result = __( 'No issues detected, everything is running smoothly.', 'optimole-wp' );
875-
}
876-
877-
return $this->response( '<ul>' . $result . '</ul>', $status );
878-
}
879-
880816
/**
881817
* Get total number of images.
882818
*

phpcs.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@
5252
<!-- Disallow long array syntax -->
5353
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
5454
<rule ref="WordPress-Docs">
55+
</rule>
56+
<rule ref="WordPress.WP.I18n.MissingTranslatorsComment"/>
5557

58+
<rule ref="WordPress.WP.I18n">
59+
<properties>
60+
<property name="text_domain" type="array">
61+
<element value="optimole-wp"/>
62+
</property>
63+
</properties>
5664
</rule>
5765
<rule ref="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing">
5866
<severity>0</severity>

0 commit comments

Comments
 (0)