diff --git a/src/components/header/SearchBar.js b/src/components/header/SearchBar.js index e4c99bf..c92560f 100644 --- a/src/components/header/SearchBar.js +++ b/src/components/header/SearchBar.js @@ -12,12 +12,14 @@ import SearchIcon from "@mui/icons-material/Search"; import KeyboardReturnIcon from "@mui/icons-material/KeyboardReturn"; import { useNavigate, useLocation } from "react-router-dom"; import { useTranslation } from "react-i18next"; +import { LanguageContext } from "../../i18n/withTranslation.js"; const SearchBar = () => { const navigate = useNavigate(); const location = useLocation(); const searchParams = new URLSearchParams(location.search); - const { t } = useTranslation(); + const { t, i18n } = useTranslation(); + const languageContext = React.useContext(LanguageContext); // State management const [searchQuery, setSearchQuery] = React.useState( @@ -64,11 +66,15 @@ const SearchBar = () => { return; } + const currentLanguage = languageContext?.currentLanguage || i18n?.language || 'de'; + window.socketManager.emit( "getSearchProducts", { query: query.trim(), limit: 8, + language: currentLanguage, + requestTranslation: currentLanguage === 'de' ? false : true, }, (response) => { if (response && response.products) { @@ -85,7 +91,7 @@ const SearchBar = () => { } ); }, - [] + [languageContext, i18n] ); const handleSearchChange = (e) => {