From 26ef53c999ace75259ccf366d5107c0c99973f7c Mon Sep 17 00:00:00 2001 From: Fredrik Johansson Date: Thu, 20 Jul 2023 14:47:47 +0200 Subject: [PATCH] fix: Use translations for content types in search results --- .../src/components/search-hits/DefaultSearchHit.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-plugin-search/src/components/search-hits/DefaultSearchHit.js b/packages/gatsby-plugin-search/src/components/search-hits/DefaultSearchHit.js index dec6bc13..c5e2b99d 100644 --- a/packages/gatsby-plugin-search/src/components/search-hits/DefaultSearchHit.js +++ b/packages/gatsby-plugin-search/src/components/search-hits/DefaultSearchHit.js @@ -3,6 +3,7 @@ import { useContentType } from "@whitespace/gatsby-theme-wordpress-basic/src/hoo import { memoize } from "lodash-es"; import PropTypes from "prop-types"; import React from "react"; +import { useTranslation } from "react-i18next"; import DeprecatedSearchHit from "../SearchHit"; import SearchTeaser from "../SearchTeaser"; @@ -34,6 +35,7 @@ export default function DefaultSearchHit({ hit, ...restProps }) { + const { t } = useTranslation(); const contentType = useContentType(hit.contentType); if (DeprecatedSearchHit) { @@ -52,15 +54,20 @@ export default function DefaultSearchHit({ // taxonomies, } = hit; + let contentTypeName = t( + [`contentTypes.${contentType.name}.name`, contentType.labels?.singularName], + { + count: 1, + }, + ); + return ( {label} {text && {text}} - {contentType?.labels?.name && ( - {contentType.labels.singularName} - )} + {!!contentTypeName && {contentTypeName}} {date &&