22import { __ , sprintf } from "@wordpress/i18n" ;
33import { Code } from "@yoast/ui-library" ;
44import { createInterpolateElement } from "@wordpress/element" ;
5- import { omit , reduce , times , toLower , filter , includes , isEmpty } from "lodash" ;
5+ import { omit , reduce , times , filter , includes , isEmpty } from "lodash" ;
6+ import { safeToLocaleLower } from "./i18n" ;
67
78/**
89 * @param {Object } postType The post type.
10+ * @param {Object } options The options.
11+ * @param {string } options.userLocale The user locale string.
912 * @returns {Object } The search index for the post type.
1013 */
11- export const createPostTypeSearchIndex = ( { name, label, route, hasArchive } ) => ( {
14+ export const createPostTypeSearchIndex = ( { name, label, route, hasArchive } , { userLocale } ) => ( {
1215 [ `title-${ name } ` ] : {
1316 route : `/post-type/${ route } ` ,
1417 routeLabel : label ,
@@ -30,7 +33,7 @@ export const createPostTypeSearchIndex = ( { name, label, route, hasArchive } )
3033 fieldLabel : sprintf (
3134 // translators: %1$s expands to the post type plural, e.g. Posts.
3235 __ ( "Show %1$s in search results" , "wordpress-seo" ) ,
33- toLower ( label )
36+ safeToLocaleLower ( label , userLocale )
3437 ) ,
3538 keywords : [ ] ,
3639 } ,
@@ -120,7 +123,7 @@ export const createPostTypeSearchIndex = ( { name, label, route, hasArchive } )
120123 fieldLabel : sprintf (
121124 // translators: %1$s expands to the post type plural, e.g. Posts.
122125 __ ( "Show the archive for %1$s in search results" , "wordpress-seo" ) ,
123- toLower ( label )
126+ safeToLocaleLower ( label , userLocale )
124127 ) ,
125128 keywords : [ ] ,
126129 } ,
@@ -150,9 +153,11 @@ export const createPostTypeSearchIndex = ( { name, label, route, hasArchive } )
150153
151154/**
152155 * @param {Object } taxonomy The taxonomy.
156+ * @param {Object } options The options.
157+ * @param {string } options.userLocale The user locale string.
153158 * @returns {Object } The search index for the taxonomy.
154159 */
155- export const createTaxonomySearchIndex = ( { name, label, route } ) => ( {
160+ export const createTaxonomySearchIndex = ( { name, label, route } , { userLocale } ) => ( {
156161 [ `title-tax-${ name } ` ] : {
157162 route : `/taxonomy/${ route } ` ,
158163 routeLabel : label ,
@@ -175,7 +180,7 @@ export const createTaxonomySearchIndex = ( { name, label, route } ) => ( {
175180 /* translators: %1$s expands to "Yoast SEO". %2$s expands to the taxonomy plural, e.g. Categories. */
176181 __ ( "Enable %1$s for %2$s" , "wordpress-seo" ) ,
177182 "Yoast SEO" ,
178- toLower ( label )
183+ safeToLocaleLower ( label , userLocale )
179184 ) ,
180185 keywords : [ ] ,
181186 } ,
@@ -193,7 +198,7 @@ export const createTaxonomySearchIndex = ( { name, label, route } ) => ( {
193198 fieldLabel : sprintf (
194199 // translators: %1$s expands to the taxonomy plural, e.g. Categories.
195200 __ ( "Show %1$s in search results" , "wordpress-seo" ) ,
196- toLower ( label )
201+ safeToLocaleLower ( label , userLocale )
197202 ) ,
198203 keywords : [ ] ,
199204 } ,
@@ -232,9 +237,11 @@ export const createTaxonomySearchIndex = ( { name, label, route } ) => ( {
232237/**
233238 * @param {Object } postTypes The post types.
234239 * @param {Object } taxonomies The taxonomies.
240+ * @param {Object } options The options.
241+ * @param {string } options.userLocale The user locale string.
235242 * @returns {Object } The search index.
236243 */
237- export const createSearchIndex = ( postTypes , taxonomies ) => ( {
244+ export const createSearchIndex = ( postTypes , taxonomies , { userLocale } = { } ) => ( {
238245 blogdescription : {
239246 route : "/site-basics" ,
240247 routeLabel : __ ( "Site basics" , "wordpress-seo" ) ,
@@ -751,7 +758,7 @@ export const createSearchIndex = ( postTypes, taxonomies ) => ( {
751758 fieldId : `input-wpseo_titles-post_types-${ postType . name } -maintax` ,
752759 fieldLabel : createInterpolateElement (
753760 // translators: %1$s expands to the post type plural, e.g. posts.
754- sprintf ( __ ( "Breadcrumbs for %1$s<code />" , "wordpress-seo" ) , toLower ( postType . label ) ) ,
761+ sprintf ( __ ( "Breadcrumbs for %1$s<code />" , "wordpress-seo" ) , safeToLocaleLower ( postType . label , userLocale ) ) ,
755762 {
756763 code : < Code className = "yst-ml-2 group-hover:yst-bg-primary-200 group-hover:yst-text-primary-800" > { postType . name } </ Code > ,
757764 }
@@ -768,7 +775,7 @@ export const createSearchIndex = ( postTypes, taxonomies ) => ( {
768775 fieldId : `input-wpseo_titles-taxonomy-${ taxonomy . name } -ptparent` ,
769776 fieldLabel : createInterpolateElement (
770777 // translators: %1$s expands to the taxonomy plural, e.g. categories.
771- sprintf ( __ ( "Breadcrumbs for %1$s<code />" , "wordpress-seo" ) , toLower ( taxonomy . label ) ) ,
778+ sprintf ( __ ( "Breadcrumbs for %1$s<code />" , "wordpress-seo" ) , safeToLocaleLower ( taxonomy . label , userLocale ) ) ,
772779 {
773780 code : < Code className = "yst-ml-2 group-hover:yst-bg-primary-200 group-hover:yst-text-primary-800" > { taxonomy . name } </ Code > ,
774781 }
@@ -1056,12 +1063,12 @@ export const createSearchIndex = ( postTypes, taxonomies ) => ( {
10561063 // Post types - Attachments are handled separately above.
10571064 ...reduce ( omit ( postTypes , [ "attachment" ] ) , ( acc , postType ) => ( {
10581065 ...acc ,
1059- ...createPostTypeSearchIndex ( postType ) ,
1066+ ...createPostTypeSearchIndex ( postType , { userLocale } ) ,
10601067 } ) , { } ) ,
10611068 // Taxonomies
10621069 ...reduce ( omit ( taxonomies , [ "post_format" ] ) , ( acc , taxonomy ) => ( {
10631070 ...acc ,
1064- ...createTaxonomySearchIndex ( taxonomy ) ,
1071+ ...createTaxonomySearchIndex ( taxonomy , { userLocale } ) ,
10651072 } ) , { } ) ,
10661073 } ,
10671074 wpseo_social : {
0 commit comments