From d3ad28ba0c4dcd3322a9b650e35d911184a3f57b Mon Sep 17 00:00:00 2001 From: peijunlei Date: Wed, 9 Sep 2026 14:12:16 +0800 Subject: [PATCH] refactor(search): implement language-specific labels for search result types --- app/controller/frontend/SearchController.php | 40 ++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/app/controller/frontend/SearchController.php b/app/controller/frontend/SearchController.php index 1c2deb1..77716e1 100644 --- a/app/controller/frontend/SearchController.php +++ b/app/controller/frontend/SearchController.php @@ -113,6 +113,24 @@ class SearchController extends BaseController } /** + * 搜索结果类型展示名(随语言) + */ + private function searchKindLabel(string $kindKey): string + { + $isEn = ($this->lang === 'en'); + $map = [ + 'product' => $isEn ? 'Products' : '产品', + 'news' => $isEn ? 'News' : '新闻', + 'faq' => $isEn ? 'FAQ' : '常见问题', + 'download' => $isEn ? 'Download Center' : '下载中心', + 'video_tutorial' => $isEn ? 'Video Tutorials' : '视频教程', + 'announce' => $isEn ? 'Product Announcements' : '产品公告', + 'content' => $isEn ? 'Content' : '内容', + ]; + return $map[$kindKey] ?? ($isEn ? 'Content' : '内容'); + } + + /** * 解析搜索结果类型 * @param int $contentId 内容 ID * @param array $sets content / cate 集合(array_flip 后的 isset 表) @@ -122,29 +140,29 @@ class SearchController extends BaseController { // 产品:内容命中 或 关联栏目落在产品树 if (isset($sets['product'][$contentId]) || $this->cateIdsHit($cateIds, $sets['product_cates'] ?? [])) { - return ['product', '产品']; + return ['product', $this->searchKindLabel('product')]; } // 企业视频:交互同视频,类型名显示新闻 if (isset($sets['news_video'][$contentId]) || $this->cateIdsHit($cateIds, $sets['news_video_cates'] ?? [])) { - return ['video', '新闻']; + return ['video', $this->searchKindLabel('news')]; } if (isset($sets['news'][$contentId]) || $this->cateIdsHit($cateIds, $sets['news_cates'] ?? [])) { - return ['news', '新闻']; + return ['news', $this->searchKindLabel('news')]; } if (isset($sets['faq'][$contentId]) || $this->cateIdsHit($cateIds, $sets['faq_cates'] ?? [])) { - return ['faq', '常见问题']; + return ['faq', $this->searchKindLabel('faq')]; } // 下载中心(含社会责任报告子栏目) if (isset($sets['download'][$contentId]) || $this->cateIdsHit($cateIds, $sets['download_cates'] ?? [])) { - return ['download', '下载中心']; + return ['download', $this->searchKindLabel('download')]; } if (isset($sets['video'][$contentId]) || $this->cateIdsHit($cateIds, $sets['video_cates'] ?? [])) { - return ['video', '视频教程']; + return ['video', $this->searchKindLabel('video_tutorial')]; } if (isset($sets['announce'][$contentId]) || $this->cateIdsHit($cateIds, $sets['announce_cates'] ?? [])) { - return ['announce', '产品公告']; + return ['announce', $this->searchKindLabel('announce')]; } - return ['content', '内容']; + return ['content', $this->searchKindLabel('content')]; } /** @@ -298,9 +316,9 @@ class SearchController extends BaseController 'announce_cates' => array_flip($announceCateIds), ]; $tabKindMap = [ - 'product' => ['product', '产品'], - 'news' => ['news', '新闻'], - 'faq' => ['faq', '常见问题'], + 'product' => ['product', $this->searchKindLabel('product')], + 'news' => ['news', $this->searchKindLabel('news')], + 'faq' => ['faq', $this->searchKindLabel('faq')], ]; $newsVideoIdSet = $kindSets['news_video']; $currentLang = $this->lang;