diff --git a/includes/RestApi/RestApi.php b/includes/RestApi/RestApi.php
index 1fc377c16..0ad914434 100644
--- a/includes/RestApi/RestApi.php
+++ b/includes/RestApi/RestApi.php
@@ -33,7 +33,6 @@ final class RestApi {
'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SiteClassificationController',
'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SiteGenController',
'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\PreviewsController',
- 'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\LanguagesController',
'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\DesignController',
'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\GlobalStylesController',
);
diff --git a/includes/RestApi/SiteGenController.php b/includes/RestApi/SiteGenController.php
index 8fc729461..b91b18e5c 100644
--- a/includes/RestApi/SiteGenController.php
+++ b/includes/RestApi/SiteGenController.php
@@ -6,6 +6,7 @@
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService as LegacySiteGenService;
use NewfoldLabs\WP\Module\Onboarding\Data\SiteGen as SiteGenData;
use NewfoldLabs\WP\Module\Onboarding\Services\Ai\ContentGeneration\SitekitsContentGeneration;
+use NewfoldLabs\WP\Module\Onboarding\Services\LanguageService;
use NewfoldLabs\WP\Module\Onboarding\Services\SiteGenService;
use NewfoldLabs\WP\Module\Onboarding\Services\SiteNavigationService;
@@ -121,10 +122,6 @@ public function sitegen_meta_args() {
'required' => true,
'type' => 'string',
),
- 'locale' => array(
- 'required' => true,
- 'type' => 'string',
- ),
'skip_cache' => array(
'required' => false,
'type' => 'boolean',
@@ -148,10 +145,6 @@ public function get_homepages_args() {
'required' => true,
'type' => 'string',
),
- 'locale' => array(
- 'required' => true,
- 'type' => 'string',
- ),
);
}
@@ -235,9 +228,9 @@ public function generate_sitegen_meta( \WP_REST_Request $request ) {
}
$site_info = $request->get_param( 'site_info' );
- $identifier = $request->get_param( 'identifier' );
+ $identifier = $request->get_param( 'identifier' );
$site_type = $request->get_param( 'site_type' );
- $locale = $request->get_param( 'locale' );
+ $locale = LanguageService::get_site_locale();
$skip_cache = $request->get_param( 'skip_cache' );
return LegacySiteGenService::instantiate_site_meta(
@@ -264,7 +257,7 @@ public function get_homepages( \WP_REST_Request $request ) {
$site_description = $request->get_param( 'site_description' );
$site_info = array( 'site_description' => $site_description );
$site_type = $request->get_param( 'site_type' );
- $locale = $request->get_param( 'locale' );
+ $locale = LanguageService::get_site_locale();
$homepages = [];
if ( SitekitsContentGeneration::site_type_supported( $site_type ) ) {
@@ -272,7 +265,6 @@ public function get_homepages( \WP_REST_Request $request ) {
$homepages = $siteGenService->get_sitekits(
$site_description,
$site_type,
- $locale,
true
);
@@ -315,7 +307,7 @@ public function regenerate_homepage( \WP_REST_Request $request ) {
$color_palette = $request->get_param( 'palette' );
$is_favorite = $request->get_param( 'isFavorite' );
$site_info = array( 'site_description' => $site_description );
- $locale = $request->get_param( 'locale' );
+ $locale = LanguageService::get_site_locale();
$skip_cache = $request->get_param( 'skip_cache' );
$target_audience = LegacySiteGenService::instantiate_site_meta( $site_info, 'target_audience', $locale, $skip_cache );
@@ -356,7 +348,7 @@ public function publish_sitemap_pages( \WP_REST_Request $request ) {
$site_description = $request->get_param( 'site_description' );
$site_info = array( 'site_description' => $site_description );
$site_type = $request->get_param( 'site_type' );
- $locale = $request->get_param( 'locale' );
+ $locale = LanguageService::get_site_locale();
$skip_cache = $request->get_param( 'skip_cache' );
$target_audience = LegacySiteGenService::instantiate_site_meta( $site_info, 'target_audience', $site_type, $locale, $skip_cache );
diff --git a/includes/Services/Ai/ContentGeneration/ContentGenerationPrompt.php b/includes/Services/Ai/ContentGeneration/ContentGenerationPrompt.php
index 9727e30ea..6b87b93f8 100644
--- a/includes/Services/Ai/ContentGeneration/ContentGenerationPrompt.php
+++ b/includes/Services/Ai/ContentGeneration/ContentGenerationPrompt.php
@@ -13,6 +13,7 @@
use NewfoldLabs\WP\Module\AI\SiteGen\SiteGen;
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService as LegacySiteGenService;
+use NewfoldLabs\WP\Module\Onboarding\Services\LanguageService;
/**
* Content Generation Prompt Class
@@ -36,13 +37,6 @@ class ContentGenerationPrompt {
*/
private $site_type;
- /**
- * The locale/language code for the site.
- *
- * @var string
- */
- private $locale;
-
/**
* The required site meta dependencies.
*
@@ -59,14 +53,12 @@ class ContentGenerationPrompt {
*
* @param string $site_description The user-provided site description.
* @param string $site_type The type of site (e.g., 'business', 'personal', 'ecommerce', 'linkinbio').
- * @param string $locale The locale/language code for the site.
*/
- public function __construct( $site_description, $site_type, $locale ) {
- $this->validate_input( $site_description, $site_type, $locale );
+ public function __construct( $site_description, $site_type ) {
+ $this->validate_input( $site_description, $site_type );
$this->site_description = trim( $site_description );
$this->site_type = trim( $site_type );
- $this->locale = trim( $locale );
}
/**
@@ -74,11 +66,10 @@ public function __construct( $site_description, $site_type, $locale ) {
*
* @param string $site_description The site description.
* @param string $site_type The site type.
- * @param string $locale The locale.
*
* @throws \Exception If any parameter is empty.
*/
- private function validate_input( $site_description, $site_type, $locale ) {
+ private function validate_input( $site_description, $site_type ) {
if ( empty( $site_description ) ) {
throw new \Exception( 'Site description cannot be empty' );
}
@@ -86,10 +77,6 @@ private function validate_input( $site_description, $site_type, $locale ) {
if ( empty( $site_type ) ) {
throw new \Exception( 'Site type cannot be empty' );
}
-
- if ( empty( $locale ) ) {
- throw new \Exception( 'Locale cannot be empty' );
- }
}
/**
@@ -113,7 +100,7 @@ private function get_meta_response( $site_meta_dependency ): array {
$this->site_description,
$site_meta_dependency,
$this->site_type,
- $this->locale
+ LanguageService::get_site_locale()
);
if ( is_wp_error( $response ) ) {
diff --git a/includes/Services/Ai/ContentGeneration/SitekitsContentGeneration.php b/includes/Services/Ai/ContentGeneration/SitekitsContentGeneration.php
index ec3eb582d..4b9b0c7ef 100644
--- a/includes/Services/Ai/ContentGeneration/SitekitsContentGeneration.php
+++ b/includes/Services/Ai/ContentGeneration/SitekitsContentGeneration.php
@@ -2,6 +2,7 @@
namespace NewfoldLabs\WP\Module\Onboarding\Services\Ai\ContentGeneration;
+use NewfoldLabs\WP\Module\Onboarding\Services\LanguageService;
use NewfoldLabs\WP\Module\Onboarding\Services\SiteGenService;
use NewfoldLabs\WP\Module\Onboarding\Services\SiteTypes\EcommerceSiteTypeService;
use NewfoldLabs\WP\Module\Onboarding\Services\SiteTypes\CommonSiteTypeService;
@@ -23,13 +24,6 @@ class SitekitsContentGeneration {
*/
private $site_type;
- /**
- * The locale.
- *
- * @var string
- */
- private $locale;
-
/**
* The prompt.
*
@@ -48,13 +42,11 @@ class SitekitsContentGeneration {
* Constructor.
*
* @param string $site_type The site type.
- * @param string $locale The locale.
* @param ContentGenerationPrompt $prompt The prompt.
* @param SiteClassification $site_classification The site classification.
*/
- public function __construct( string $site_type, string $locale, ContentGenerationPrompt $prompt, SiteClassification $site_classification ) {
+ public function __construct( string $site_type, ContentGenerationPrompt $prompt, SiteClassification $site_classification ) {
$this->site_type = $site_type;
- $this->locale = $locale;
$this->prompt = $prompt;
$this->site_classification = $site_classification;
}
@@ -71,7 +63,7 @@ public function generate_sitekits( int $count = 3 ) {
'siteType' => $this->site_type,
'count' => $count,
'prompt' => $prompt,
- 'locale' => $this->locale,
+ 'locale' => LanguageService::get_site_locale(),
'primaryType' => $this->site_classification->get_primary_type(),
'secondaryType' => $this->site_classification->get_secondary_type(),
);
diff --git a/includes/Services/LanguageService.php b/includes/Services/LanguageService.php
index 39cf0e3c3..7688588ed 100644
--- a/includes/Services/LanguageService.php
+++ b/includes/Services/LanguageService.php
@@ -2,6 +2,8 @@
namespace NewfoldLabs\WP\Module\Onboarding\Services;
+use NewfoldLabs\WP\Module\Onboarding\Data\Languages;
+
/**
* Class LanguageService
*
@@ -10,92 +12,16 @@
class LanguageService {
/**
- * Get all available languages including the default English.
+ * Get the site locale.
*
- * @return array List of language data
+ * @return string The site locale.
*/
- public static function get_all_languages() {
- // Load translation-install.php if the function doesn't exist
- if ( ! function_exists( 'wp_get_available_translations' ) ) {
- require_once ABSPATH . 'wp-admin/includes/translation-install.php';
- }
-
- // Get all available translations from WordPress API
- $translations = \wp_get_available_translations();
-
- // If translations API fails, provide basic fallback
- if ( empty( $translations ) ) {
- return self::get_fallback_languages();
+ public static function get_site_locale(): string {
+ $locale = Languages::get_default_language();
+ if ( ! $locale ) {
+ // Fallback to en_US if no default language is found.
+ $locale = 'en_US';
}
-
- // Format data for response - include English as default
- $formatted_languages = array(
- array(
- 'code' => 'en_US',
- 'name' => 'English (United States)',
- 'native_name' => 'English (United States)',
- ),
- );
-
- // Add translated languages with proper format
- foreach ( $translations as $locale => $translation ) {
- $formatted_languages[] = array(
- 'code' => $locale,
- 'name' => $translation['english_name'],
- 'native_name' => $translation['native_name'],
- );
- }
-
- return $formatted_languages;
- }
-
- /**
- * Get language data array formatted for the language selection component.
- * Returns array of [language_name, language_code] pairs.
- *
- * @return array Array of language name and code pairs
- */
- public static function get_languages_for_selection() {
- $languages = self::get_all_languages();
- $language_list = array();
-
- foreach ( $languages as $language ) {
- $language_list[] = array(
- $language['name'],
- $language['code'],
- );
- }
-
- return $language_list;
- }
-
- /**
- * Get fallback languages in case the translations API fails.
- *
- * @return array Basic list of language data
- */
- private static function get_fallback_languages() {
- return array(
- array(
- 'code' => 'en_US',
- 'name' => 'English (United States)',
- 'native_name' => 'English (United States)',
- ),
- array(
- 'code' => 'es_ES',
- 'name' => 'Spanish (Spain)',
- 'native_name' => 'Español',
- ),
- array(
- 'code' => 'fr_FR',
- 'name' => 'French (France)',
- 'native_name' => 'Français',
- ),
- array(
- 'code' => 'de_DE',
- 'name' => 'German',
- 'native_name' => 'Deutsch',
- ),
- );
+ return $locale;
}
}
diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php
index 9af59a2dc..52b6e02a5 100644
--- a/includes/Services/SiteGenService.php
+++ b/includes/Services/SiteGenService.php
@@ -71,15 +71,14 @@ public static function get_instance(): SiteGenService {
*
* @param string $site_description The site description.
* @param string $site_type The site type.
- * @param string $locale The locale.
* @param bool $for_onboarding_preview Whether to return the sitekits as array for onboarding preview.
* @return array|\WP_Error Array of Sitekit objects, array of sitekits for onboarding preview, or WP_Error if there is an error.
*/
- public function get_sitekits( string $site_description, string $site_type, string $locale = 'en_US', bool $for_onboarding_preview = false ) {
- $prompt = new ContentGenerationPrompt( $site_description, $site_type, $locale );
+ public function get_sitekits( string $site_description, string $site_type, bool $for_onboarding_preview = false ) {
+ $prompt = new ContentGenerationPrompt( $site_description, $site_type );
$site_classification = $this->get_site_classification();
- $sitekits = new SitekitsContentGeneration( $site_type, $locale, $prompt, $site_classification );
+ $sitekits = new SitekitsContentGeneration( $site_type, $prompt, $site_classification );
$sitekits = $sitekits->generate_sitekits();
// If there is an error, return it.
@@ -159,7 +158,7 @@ public function publish_homepage( string $selected_sitegen_homepage ) {
*/
public function get_sitemap_page_title( string $slug ) {
$prompt = $this->get_prompt();
- $locale = $this->get_locale();
+ $locale = LanguageService::get_site_locale();
$site_type = $this->get_site_type();
if ( ! $prompt || ! $locale || ! $site_type ) {
return false;
@@ -190,7 +189,7 @@ public function get_site_classification(): SiteClassification {
$this->get_prompt(),
'site_classification',
$this->get_site_type(),
- $this->get_locale()
+ LanguageService::get_site_locale()
);
if ( is_array( $site_classification ) ) {
@@ -211,7 +210,7 @@ public function get_color_palette() {
$this->get_prompt(),
'color_palette',
$this->get_site_type(),
- $this->get_locale()
+ LanguageService::get_site_locale()
);
if ( ! is_array( $color_palettes ) ) {
@@ -254,13 +253,4 @@ public function get_prompt() {
public function get_site_type() {
return ! empty( $this->input_data['siteType'] ) ? $this->input_data['siteType'] : 'business';
}
-
- /**
- * Get the locale entered during Onboarding.
- *
- * @return string
- */
- public function get_locale() {
- return ! empty( $this->input_data['locale'] ) ? $this->input_data['locale'] : 'en_US';
- }
}
diff --git a/includes/Services/SiteNavigationService.php b/includes/Services/SiteNavigationService.php
index 902398037..845efb0e9 100644
--- a/includes/Services/SiteNavigationService.php
+++ b/includes/Services/SiteNavigationService.php
@@ -45,7 +45,7 @@ public function get_site_navigation_items( $site_type = null ): array {
$this->get_prompt(),
'sitemap',
$site_type,
- $this->get_locale()
+ LanguageService::get_site_locale()
);
$nav_items = array();
diff --git a/src/app/data/store/slices/input.js b/src/app/data/store/slices/input.js
index 870ac8311..2fe8badc6 100644
--- a/src/app/data/store/slices/input.js
+++ b/src/app/data/store/slices/input.js
@@ -4,7 +4,6 @@ import { updateOnboardingInputSlice } from '@/utils/api';
const DEFAULT_STATE = {
siteTitle: '',
- selectedLocale: '',
prompt: '',
logo: '',
experienceLevel: '',
@@ -30,11 +29,6 @@ export function input( state = DEFAULT_STATE, action ) {
...state,
siteTitle: action.siteTitle,
};
- case 'SET_SELECTED_LOCALE':
- return {
- ...state,
- selectedLocale: action.selectedLocale,
- };
case 'SET_PROMPT':
return {
...state,
@@ -77,10 +71,6 @@ export const actions = {
type: 'SET_SITE_TITLE',
siteTitle,
} ),
- setSelectedLocale: ( selectedLocale ) => ( {
- type: 'SET_SELECTED_LOCALE',
- selectedLocale,
- } ),
setPrompt: ( prompt ) => ( {
type: 'SET_PROMPT',
prompt,
@@ -105,7 +95,6 @@ export const actions = {
export const selectors = {
getInputSlice: ( state ) => state.input,
getSiteTitle: ( state ) => state.input.siteTitle,
- getSelectedLocale: ( state ) => state.input.selectedLocale,
getPrompt: ( state ) => state.input.prompt,
getLogo: ( state ) => state.input.logo,
getExperienceLevel: ( state ) => state.input.experienceLevel,
diff --git a/src/app/data/store/slices/runtime.js b/src/app/data/store/slices/runtime.js
index 4fe09ea24..049113423 100644
--- a/src/app/data/store/slices/runtime.js
+++ b/src/app/data/store/slices/runtime.js
@@ -117,6 +117,17 @@ export const selectors = {
return Object.values( state.runtime.languages );
},
+ /**
+ * Gets the current locale.
+ *
+ * @param {*} state
+ * @return {string} locale
+ */
+ getLocale( state ) {
+ const languages = Object.values( state.runtime.languages );
+ return languages.find( ( language ) => language.is_default )?.locale || 'en_US';
+ },
+
/**
* Gets all available sitegen identifiers.
*
diff --git a/src/app/steps/Intake/IntakeStep.js b/src/app/steps/Intake/IntakeStep.js
index b85193cb3..40371b4a6 100644
--- a/src/app/steps/Intake/IntakeStep.js
+++ b/src/app/steps/Intake/IntakeStep.js
@@ -6,17 +6,16 @@ import { Navigate, Step } from '@/components';
import { nfdOnboardingStore } from '@/data/store';
import { OnboardingEvent, trackOnboardingEvent } from '@/utils/analytics/hiive';
import { ACTION_INTAKE_PROMPT_SET, ACTION_SITE_TYPE_SET } from '@/utils/analytics/hiive/constants';
-import { SiteTitleInput, PromptInput, LanguageSelector, calculatePromptStrength, SiteTypeSelector } from '.';
+import { SiteTitleInput, PromptInput, calculatePromptStrength, SiteTypeSelector } from '.';
const IntakeStep = () => {
// Initiale state values.
- const { siteType, siteTitle, selectedLocale, prompt } = select( nfdOnboardingStore ).getInputSlice();
+ const { siteType, siteTitle, prompt } = select( nfdOnboardingStore ).getInputSlice();
const retryMode = select( nfdOnboardingStore ).getRetryMode();
// Step states.
const [ siteTypeValue, setSiteTypeValue ] = useState( siteType );
const [ siteTitleValue, setSiteTitleValue ] = useState( siteTitle );
- const [ selectedLocaleValue, setSelectedLocaleValue ] = useState( selectedLocale );
const [ promptValue, setPromptValue ] = useState( prompt );
/**
@@ -39,7 +38,6 @@ const IntakeStep = () => {
dispatch( nfdOnboardingStore ).setInputSlice( {
siteType: siteTypeValue,
siteTitle: siteTitleValue.trim(),
- selectedLocale: selectedLocaleValue,
prompt: promptValue.trim(),
} );
@@ -96,10 +94,9 @@ const IntakeStep = () => {