Skip to content

Commit 1786774

Browse files
committed
Move strings to translatable files
1 parent 8eaf3b8 commit 1786774

File tree

4 files changed

+131
-24
lines changed

4 files changed

+131
-24
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { __ } from '@wordpress/i18n';
2+
3+
const getFontOptimizationText = () => ( {
4+
fontOptimizationTitle: __( 'Font Optimization', 'wp-module-performance' ),
5+
fontOptimizationDescription: __(
6+
'Improve load times by replacing Google Fonts with optimized local versions.',
7+
'wp-module-performance'
8+
),
9+
fontOptimizationLabel: __(
10+
'Optimize Fonts via Cloudflare',
11+
'wp-module-performance'
12+
),
13+
fontOptimizationToggleDescription: __(
14+
'Replaces Google Fonts with faster, privacy-friendly versions served locally.',
15+
'wp-module-performance'
16+
),
17+
fontOptimizationUpsellText: __(
18+
'Upgrade to enable font optimization using Cloudflare.',
19+
'wp-module-performance'
20+
),
21+
fontOptimizationUpsellLink: __(
22+
'https://www.bluehost.com',
23+
'wp-module-performance'
24+
),
25+
fontOptimizationLoading: __(
26+
'Loading font optimization settings…',
27+
'wp-module-performance'
28+
),
29+
fontOptimizationError: __(
30+
'Error loading settings.',
31+
'wp-module-performance'
32+
),
33+
fontOptimizationUpdatedTitle: __(
34+
'Fonts optimization updated',
35+
'wp-module-performance'
36+
),
37+
fontOptimizationUpdatedDescription: __(
38+
'Font optimization setting saved successfully.',
39+
'wp-module-performance'
40+
),
41+
fontOptimizationErrorTitle: __( 'Update failed', 'wp-module-performance' ),
42+
fontOptimizationErrorDescription: __(
43+
'Could not save font optimization setting.',
44+
'wp-module-performance'
45+
),
46+
} );
47+
48+
export default getFontOptimizationText;

src/sections/FontOptimization/index.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import apiFetch from '@wordpress/api-fetch';
99
import { useDispatch } from '@wordpress/data';
1010
import { STORE_NAME } from '../../data/constants';
1111
import { NewfoldRuntime } from '@newfold/wp-module-runtime';
12+
import getFontOptimizationText from './getFontOptimizationText';
1213

1314
const FontOptimization = () => {
1415
const [ settings, setSettings ] = useState( null );
@@ -17,6 +18,20 @@ const FontOptimization = () => {
1718

1819
const { pushNotification } = useDispatch( STORE_NAME );
1920
const apiUrl = NewfoldRuntime.createApiUrl( '/wp/v2/settings' );
21+
const {
22+
fontOptimizationTitle,
23+
fontOptimizationDescription,
24+
fontOptimizationLabel,
25+
fontOptimizationToggleDescription,
26+
fontOptimizationUpsellText,
27+
fontOptimizationUpsellLink,
28+
fontOptimizationLoading,
29+
fontOptimizationError,
30+
fontOptimizationUpdatedTitle,
31+
fontOptimizationUpdatedDescription,
32+
fontOptimizationErrorTitle,
33+
fontOptimizationErrorDescription,
34+
} = getFontOptimizationText();
2035

2136
const fetchSettings = async () => {
2237
setIsLoading( true );
@@ -42,16 +57,16 @@ const FontOptimization = () => {
4257
} );
4358
setSettings( newSettings );
4459
pushNotification( 'font-opt-updated', {
45-
title: 'Fonts optimization updated',
46-
description: 'Font optimization setting saved successfully.',
60+
title: fontOptimizationUpdatedTitle,
61+
description: fontOptimizationUpdatedDescription,
4762
variant: 'success',
4863
autoDismiss: 5000,
4964
} );
5065
} catch {
5166
setIsError( true );
5267
pushNotification( 'font-opt-error', {
53-
title: 'Update failed',
54-
description: 'Could not save font optimization setting.',
68+
title: fontOptimizationErrorTitle,
69+
description: fontOptimizationErrorDescription,
5570
variant: 'error',
5671
autoDismiss: 8000,
5772
} );
@@ -74,9 +89,10 @@ const FontOptimization = () => {
7489
fetchSettings();
7590
}, [] );
7691

77-
if ( isLoading ) return <p>Loading font optimization settings…</p>;
92+
if ( isLoading ) return <p>{ fontOptimizationLoading }</p>;
7893
if ( isError )
79-
return <Alert variant="error">Error loading settings.</Alert>;
94+
return <Alert variant="error">{ fontOptimizationError }</Alert>;
95+
8096
if ( ! settings ) return null;
8197

8298
const isEnabled = settings?.cloudflare?.fonts || false;
@@ -85,26 +101,26 @@ const FontOptimization = () => {
85101

86102
return (
87103
<Container.SettingsField
88-
title="Font Optimization"
89-
description="Improve load times by replacing Google Fonts with optimized local versions."
104+
title={ fontOptimizationTitle }
105+
description={ fontOptimizationDescription }
90106
>
91107
{ hasCapability ? (
92108
<ToggleField
93109
id="cloudflare-fonts"
94-
label="Optimize Fonts via Cloudflare"
95-
description="Replaces Google Fonts with faster, privacy-friendly versions served locally."
110+
label={ fontOptimizationLabel }
111+
description={ fontOptimizationToggleDescription }
96112
checked={ isEnabled }
97113
onChange={ () => handleToggle( ! isEnabled ) }
98114
/>
99115
) : (
100116
<FeatureUpsell
101-
cardText="Upgrade to enable font optimization using Cloudflare."
102-
cardLink="https://www.bluehost.com"
117+
cardText={ fontOptimizationUpsellText }
118+
cardLink={ fontOptimizationUpsellLink }
103119
>
104120
<ToggleField
105121
id="cloudflare-fonts"
106-
label="Optimize Fonts via Cloudflare"
107-
description="Replaces Google Fonts with faster, privacy-friendly versions served locally."
122+
label={ fontOptimizationLabel }
123+
description={ fontOptimizationToggleDescription }
108124
checked={ false }
109125
disabled
110126
/>

src/sections/ImageOptimization/getImageOptimizationText.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,31 @@ const getImageOptimizationText = () => ( {
107107
'Something went wrong while updating the settings. Please try again.',
108108
'wp-module-performance'
109109
),
110+
imageOptimizationPolishLabel: __(
111+
'Optimize Images via Cloudflare',
112+
'wp-module-performance'
113+
),
114+
imageOptimizationPolishDescription: __(
115+
"Enables Cloudflare's image compression to reduce load times and bandwidth usage.",
116+
'wp-module-performance'
117+
),
118+
imageOptimizationMirageLabel: __(
119+
'Improve Image Loading on Slow Connections',
120+
'wp-module-performance'
121+
),
122+
imageOptimizationMirageDescription: __(
123+
"Cloudflare Mirage accelerates image loading for mobile and slow networks.",
124+
'wp-module-performance'
125+
),
126+
imageOptimizationUpsellText: __(
127+
'Get advanced image optimization features with Cloudflare Polish & Mirage.',
128+
'wp-module-performance'
129+
),
130+
imageOptimizationUpsellLink: __(
131+
'https://www.bluehost.com',
132+
'wp-module-performance'
133+
),
134+
110135
} );
111136

112137
export default getImageOptimizationText;

src/sections/ImageOptimization/index.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ const ImageOptimization = () => {
3939
imageOptimizationUpdatedDescription,
4040
imageOptimizationUpdateErrorTitle,
4141
imageOptimizationGenericErrorMessage,
42+
imageOptimizationUpsellText,
43+
imageOptimizationUpsellLink,
44+
imageOptimizationPolishLabel,
45+
imageOptimizationPolishDescription,
46+
imageOptimizationMirageLabel,
47+
imageOptimizationMirageDescription,
4248
} = getImageOptimizationText();
4349

4450
const [ settings, setSettings ] = useState( null );
@@ -340,20 +346,28 @@ const ImageOptimization = () => {
340346
) && (
341347
<div>
342348
<FeatureUpsell
343-
cardText="Get advanced image optimization features with Cloudflare Polish & Mirage."
344-
cardLink="https://www.bluehost.com"
349+
cardText={ imageOptimizationUpsellText }
350+
cardLink={ imageOptimizationUpsellLink }
345351
>
346352
<ToggleField
347353
id="cloudflare-polish"
348-
label="Optimize Images via Cloudflare"
349-
description="Enables Cloudflare's image compression to reduce load times and bandwidth usage."
354+
label={
355+
imageOptimizationPolishLabel
356+
}
357+
description={
358+
imageOptimizationPolishDescription
359+
}
350360
checked={ false }
351361
disabled
352362
/>{ ' ' }
353363
<ToggleField
354364
id="cloudflare-mirage"
355-
label="Improve Image Loading on Slow Connections"
356-
description="Cloudflare Mirage accelerates image loading for mobile and slow networks."
365+
label={
366+
imageOptimizationMirageLabel
367+
}
368+
description={
369+
imageOptimizationMirageDescription
370+
}
357371
checked={ false }
358372
disabled
359373
/>{ ' ' }
@@ -365,8 +379,10 @@ const ImageOptimization = () => {
365379
) && (
366380
<ToggleField
367381
id="cloudflare-polish"
368-
label="Optimize Images via Cloudflare"
369-
description="Enables Cloudflare's image compression to reduce load times and bandwidth usage."
382+
label={ imageOptimizationPolishLabel }
383+
description={
384+
imageOptimizationPolishDescription
385+
}
370386
checked={ polish }
371387
onChange={ () =>
372388
handleToggle( 'cloudflarePolish', ! polish )
@@ -378,8 +394,10 @@ const ImageOptimization = () => {
378394
) && (
379395
<ToggleField
380396
id="cloudflare-mirage"
381-
label="Improve Image Loading on Slow Connections"
382-
description="Cloudflare Mirage accelerates image loading for mobile and slow networks."
397+
label={ imageOptimizationMirageLabel }
398+
description={
399+
imageOptimizationMirageDescription
400+
}
383401
checked={ mirage }
384402
onChange={ () =>
385403
handleToggle( 'cloudflareMirage', ! mirage )

0 commit comments

Comments
 (0)