Skip to content

Commit

Permalink
Help Center: localize queries (#93791)
Browse files Browse the repository at this point in the history
Co-authored-by: escapemanuele <escapemanuele@gmail.com>
  • Loading branch information
heavyweight and escapemanuele authored Sep 2, 2024
1 parent 151c7e4 commit 90f7698
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useSelect } from '@wordpress/data';
import urlMapping from '../route-to-query-mapping.json';
import { useQueryForRoute } from '../route-to-query-mapping';

interface CoreBlockEditor {
getSelectedBlock: () => object;
Expand All @@ -25,15 +25,7 @@ export function useContextBasedSearchMapping( currentRoute: string | undefined )
return '';
}, [] );

// Fuzzier matches
const urlMatchKey = Object.keys( urlMapping ).find( ( key ) => currentRoute?.startsWith( key ) );
const urlSearchQuery = urlMatchKey ? urlMapping[ urlMatchKey as keyof typeof urlMapping ] : '';

// Find exact URL matches
const exactMatch = urlMapping[ currentRoute as keyof typeof urlMapping ];
if ( exactMatch ) {
return { contextSearch: exactMatch };
}
const urlSearchQuery = useQueryForRoute( currentRoute ?? '' );

return {
contextSearch: blockSearchQuery || urlSearchQuery || '',
Expand Down
44 changes: 0 additions & 44 deletions packages/help-center/src/route-to-query-mapping.json

This file was deleted.

58 changes: 58 additions & 0 deletions packages/help-center/src/route-to-query-mapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { __ } from '@wordpress/i18n';

export const useQueryForRoute = ( currentRoute: string ) => {
const urlMapping = {
'/add-ons/': __( 'add-ons' ),
'/advertising/': __( 'advertising' ),
'/comments/': __( 'comments' ),
'/discover': __( 'discover blogs' ),
'/email/': __( 'manage emails' ),
'/hosting-config/': __( 'hosting configuration' ),
'/marketing/business-tools/': __( 'business tools' ),
'/marketing/sharing-buttons/': __( 'social share' ),
'/me/get-apps': __( 'wordpress apps' ),
'/me/notifications': __( 'notification settings' ),
'/me/privacy': __( 'privacy' ),
'/me/site-blocks': __( 'blocked sites' ),
'/plans/': __( 'upgrade plan' ),
'/plugins': __( 'plugins' ),
'/plugins/manage': __( 'manage plugins' ),
'/read': __( 'reader' ),
'/read/conversations': __( 'conversations' ),
'/read/list': __( 'reader list' ),
'/read/notifications': __( 'notifications' ),
'/read/search': __( 'search' ),
'/read/subscriptions': __( 'manage subscriptions' ),
'/settings/performance/': __( 'performance settings' ),
'/settings/podcasting/': __( 'podcasting' ),
'/settings/reading/': __( 'reading settings' ),
'/settings/taxonomies/category/': __( 'site categories' ),
'/settings/taxonomies/post_tag/': __( 'post tag' ),
'/settings/writing/': __( 'writing settings' ),
'/sites': __( 'manage sites' ),
'/subscribers': __( 'subscribers' ),
'/tags': __( 'tags' ),
'/woocommerce': __( 'woocommerce' ),
'/wp-admin/admin.php?page=akismet-key-config': __( 'site spam' ),
'/wp-admin/admin.php?page=jetpack-search': __( 'jetpack search' ),
'/wp-admin/admin.php?page=polls': __( 'crowdsignal' ),
'/wp-admin/admin.php?page=ratings': __( 'ratings' ),
'/wp-admin/admin.php?page=wc': __( 'woocommerce' ),
'/wp-admin/edit.php?post_type=feedback': __( 'feedback form' ),
'/wp-admin/edit.php?post_type=jetpack-testimonial': __( 'testimonials' ),
'/wp-admin/index.php?page=my-blogs': __( 'my sites' ),
'/wp-admin/options-general.php?page=debug-bar-extender': __( 'debug bar extender' ),
'/wp-admin/options-media.php': __( 'media settings' ),
'/wp-admin/post-new.php?post_type=jetpack-testimonial': __( 'new testimonial' ),
};

// Find exact URL matches
const exactMatch = urlMapping[ currentRoute as keyof typeof urlMapping ];
if ( exactMatch ) {
return exactMatch;
}

// Fuzzier matches
const urlMatchKey = Object.keys( urlMapping ).find( ( key ) => currentRoute?.startsWith( key ) );
return urlMatchKey ? urlMapping[ urlMatchKey as keyof typeof urlMapping ] : '';
};

0 comments on commit 90f7698

Please sign in to comment.