Skip to content

Commit 7f1c130

Browse files
committed
add locale support
1 parent ffae20b commit 7f1c130

File tree

9 files changed

+98
-12
lines changed

9 files changed

+98
-12
lines changed

includes/RestApi/SiteGenController.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public function sitegen_meta_args() {
116116
'required' => true,
117117
'type' => 'string',
118118
),
119+
'locale' => array(
120+
'required' => true,
121+
'type' => 'string',
122+
),
119123
'skip_cache' => array(
120124
'required' => false,
121125
'type' => 'boolean',
@@ -135,6 +139,10 @@ public function get_homepages_args() {
135139
'type' => 'string',
136140
'sanitize_callback' => 'sanitize_text_field',
137141
),
142+
'locale' => array(
143+
'required' => true,
144+
'type' => 'string',
145+
),
138146
);
139147
}
140148

@@ -204,10 +212,13 @@ public function generate_sitegen_meta( \WP_REST_Request $request ) {
204212

205213
$site_info = $request->get_param( 'site_info' );
206214
$identifier = $request->get_param( 'identifier' );
215+
$locale = $request->get_param( 'locale' );
207216
$skip_cache = $request->get_param( 'skip_cache' );
208217

209218
// TODO Implement the main function and do computations if required.
210-
return SiteGenService::instantiate_site_meta( $site_info, $identifier, $skip_cache );
219+
return SiteGenService::instantiate_site_meta(
220+
$site_info, $identifier, $locale, $skip_cache
221+
);
211222
}
212223

213224
/**
@@ -223,22 +234,24 @@ public function get_homepages( \WP_REST_Request $request ) {
223234
}
224235

225236
$site_description = $request->get_param( 'site_description' );
237+
$locale = $request->get_param( 'locale' );
226238
$site_info = array( 'site_description' => $site_description );
227239

228-
$target_audience = SiteGenService::instantiate_site_meta( $site_info, 'target_audience' );
240+
$target_audience = SiteGenService::instantiate_site_meta( $site_info, 'target_audience', $locale );
229241
if ( is_wp_error( $target_audience ) ) {
230242
return $target_audience;
231243
}
232244

233-
$content_style = SiteGenService::instantiate_site_meta( $site_info, 'content_tones' );
245+
$content_style = SiteGenService::instantiate_site_meta( $site_info, 'content_tones', $locale );
234246
if ( is_wp_error( $content_style ) ) {
235247
return $content_style;
236248
}
237249

238250
$homepages = SiteGenService::generate_homepages(
239251
$site_description,
240252
$content_style,
241-
$target_audience
253+
$target_audience,
254+
$locale,
242255
);
243256

244257
if ( is_wp_error( $homepages ) ) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { memo } from "@wordpress/element";
2+
3+
const LanguageSelection = ( {
4+
labgeageSelectionLabel, languageList, selectedLocale, setSelectedLocale
5+
} ) => {
6+
return <div className={'nfd-sg-language'}>
7+
<label htmlFor={"nfd-site-output__languages"} className={'nfd-sg-language__label'}>{ labgeageSelectionLabel }</label>
8+
<select
9+
className={"nfd-sg-language__select"} id={"nfd-site-output__languages"}
10+
onChange={ ( event ) => {
11+
setSelectedLocale( event.target.value )
12+
} }>
13+
<option selected>Choose a language</option>
14+
{languageList.map(([language, value]) => {
15+
return <option
16+
selected={ selectedLocale === value }
17+
key={value}
18+
value={value}
19+
>
20+
{ language }
21+
</option>
22+
})}
23+
</select>
24+
</div>;
25+
}
26+
27+
export default memo( LanguageSelection );
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.nfd-sg-language {
2+
width: 100% !important;
3+
display: flex;
4+
flex-direction: column;
5+
6+
&__label {
7+
font-size: 0.87rem;
8+
margin-top: 2%;
9+
}
10+
11+
&__select {
12+
margin-top: 1%;
13+
border-radius: 8px !important;
14+
}
15+
}

src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ const SiteGen = () => {
151151
siteInfo,
152152
identifier,
153153
skipCache,
154+
locale,
154155
retryCount = 1
155156
) {
156157
const data = await generateSiteGenMeta(
157158
siteInfo,
158159
identifier,
160+
locale,
159161
skipCache
160162
);
161163

@@ -166,6 +168,7 @@ const SiteGen = () => {
166168
siteInfo,
167169
identifier,
168170
skipCache,
171+
locale,
169172
retryCount + 1
170173
);
171174
}
@@ -234,7 +237,8 @@ const SiteGen = () => {
234237
// Get the homepages and set that in flow
235238
setIsGeneratingHomepages( true );
236239
const response = await getHomepages(
237-
currentData.sitegen.siteDetails.prompt
240+
currentData.sitegen.siteDetails.prompt,
241+
currentData.sitegen.siteDetails.locale,
238242
);
239243

240244
if ( response.error ) {
@@ -316,10 +320,12 @@ const SiteGen = () => {
316320
site_description: currentData.sitegen?.siteDetails?.prompt,
317321
};
318322

323+
const locale = currentData.sitegen?.siteDetails?.locale;
324+
319325
const skipCache = currentData.sitegen?.skipCache;
320326
// Iterate over Identifiers and fire Requests!
321327
identifiers.forEach( ( identifier ) => {
322-
performSiteGenMetaGeneration( siteInfo, identifier, skipCache );
328+
performSiteGenMetaGeneration( siteInfo, identifier, skipCache, locale );
323329
} );
324330
}
325331

src/OnboardingSPA/components/TextInput/TextInputSiteGen/stylesheet.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ $selected-detail: #1de082;
4848

4949
&_bottom {
5050
display: flex;
51-
flex-direction: row;
52-
align-items: center;
51+
flex-direction: column;
5352
justify-content: space-between;
5453
}
5554
}

src/OnboardingSPA/steps/SiteGen/Preview/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ const SiteGenPreview = () => {
108108
}
109109

110110
const response = await getHomepages(
111-
currentData.sitegen.siteDetails.prompt
111+
currentData.sitegen.siteDetails.prompt,
112+
currentData.sitegen.locale,
112113
);
113114

114115
if ( response.error ) {

src/OnboardingSPA/steps/SiteGen/SiteDetails/contents.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ const getContents = () => {
2020
'wp-module-onboarding'
2121
),
2222
walkThroughlink: __( 'click here', 'wp-module-onboarding' ),
23+
languageList: [
24+
[ __('English (US)', 'wp-module-onboarding'), 'en-US' ],
25+
[ __('English (UK)', 'wp-module-onboarding'), 'en-UK' ],
26+
[ __('Spanish', 'wp-module-onboarding'), 'es-ES' ],
27+
[ __('French', 'wp-module-onboarding'), 'fr-FR' ],
28+
[ __('Hindi', 'wp-module-onboarding'), 'hi-IN' ],
29+
],
30+
languageSelectionLabel: __( 'Choose your preferred site language:', 'wp-module-onboarding' )
2331
};
2432
};
2533

src/OnboardingSPA/steps/SiteGen/SiteDetails/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import CommonLayout from '../../../components/Layouts/Common';
1717
import TextInputSiteGen from '../../../components/TextInput/TextInputSiteGen';
1818
import NextButtonSiteGen from '../../../components/Button/NextButtonSiteGen';
1919
import { SiteGenStateHandler } from '../../../components/StateHandlers';
20+
import LanguageSelection from "../../../components/LanguageSelection";
2021

2122
// Misc
2223
import { HEADER_SITEGEN } from '../../../../constants';
@@ -26,6 +27,7 @@ import { SITEGEN_FLOW } from '../../../data/flows/constants';
2627

2728
const SiteGenSiteDetails = () => {
2829
const [ customerInput, setCustomerInput ] = useState( '' );
30+
const [ selectedLocale, setSelectedLocale ] = useState( '' );
2931
const [ customerInputStrength, setCustomerInputStrength ] = useState( 0 );
3032
const [ isValidInput, setIsValidInput ] = useState( false );
3133

@@ -66,7 +68,9 @@ const SiteGenSiteDetails = () => {
6668
currentData.sitegen.siteDetails.prompt = '';
6769
setCurrentOnboardingData( currentData );
6870
} else {
69-
setIsValidInput( true );
71+
if ( selectedLocale !== '' ) {
72+
setIsValidInput( true );
73+
}
7074
setIsFooterNavAllowed( true );
7175
}
7276
return setCustomerInput( currentData.sitegen.siteDetails.prompt );
@@ -93,14 +97,20 @@ const SiteGenSiteDetails = () => {
9397
setCurrentOnboardingData( currentData );
9498
}
9599
// Else just make sure the Next is enabled when prompt is present
96-
setIsValidInput( true );
100+
if ( selectedLocale !== '' ) {
101+
setIsValidInput( true );
102+
}
97103
setIsFooterNavAllowed( true );
98104
} else {
99105
setIsValidInput( false );
100106
setIsFooterNavAllowed( false );
101107
}
108+
109+
if ( selectedLocale !== currentData.sitegen.siteDetails.locale ) {
110+
currentData.sitegen.siteDetails.locale = selectedLocale;
111+
}
102112
}
103-
}, [ customerInput ] );
113+
}, [ customerInput, selectedLocale ] );
104114

105115
const trackPromptSetEvent = () => {
106116
let customerInputStrengthForEvent = false;
@@ -146,6 +156,12 @@ const SiteGenSiteDetails = () => {
146156
}
147157
customChildren={ true }
148158
>
159+
<LanguageSelection
160+
labgeageSelectionLabel={ content.languageSelectionLabel }
161+
languageList={ content.languageList }
162+
selectedLocale={selectedLocale}
163+
setSelectedLocale={setSelectedLocale}
164+
/>
149165
{ isLargeViewport && (
150166
<div className={ 'nfd-sg-site-details-endrow' }>
151167
<NextButtonSiteGen

src/OnboardingSPA/styles/app.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
@import "../components/TextInput/TextAreaSiteGenDetails/stylesheet";
6767
@import "../components/TextInput/TextInputSiteGenDetails/stylesheet";
6868
@import "../components/OrbAnimation/stylesheet";
69+
@import "../components/LanguageSelection/stylesheet.scss";
6970

7071
// CSS for Pages
7172
@import "../steps/BasicInfo/stylesheet";

0 commit comments

Comments
 (0)