From 9c6b7b2de1a507edafda3d0c9758cf9c1ceaa2ad Mon Sep 17 00:00:00 2001 From: Alaguraj0361 Date: Sat, 23 Aug 2025 15:23:44 +0530 Subject: [PATCH] header language change option updated for 2 languages --- components/HeaderTopbar/HeaderTopbar.js | 102 +++++++++++++++++++++--- next-i18next.config.js | 2 +- 2 files changed, 91 insertions(+), 13 deletions(-) diff --git a/components/HeaderTopbar/HeaderTopbar.js b/components/HeaderTopbar/HeaderTopbar.js index 66dda34..573512b 100644 --- a/components/HeaderTopbar/HeaderTopbar.js +++ b/components/HeaderTopbar/HeaderTopbar.js @@ -7,43 +7,120 @@ import Image from 'next/image' import { useTranslation } from 'next-i18next' import { changeLanguage } from '../../utils/commonFunction.utils' import { useRouter } from 'next/router' +import Slider from 'react-slick' const HeaderTopbar = () => { - const { t } = useTranslation('common') - + const { t, i18n } = useTranslation('common') const router = useRouter() - const handleLanguageChange = () => { - changeLanguage(router, 'es'); // always switch to Spanish - }; + const handleLanguageChange = (locale) => { + changeLanguage(router, locale) + } + + // Slider Settings + const settings = { + dots: false, + arrows: false, + infinite: true, + autoplay: true, + autoplaySpeed: 2000, + speed: 600, + slidesToShow: 1, + slidesToScroll: 1, + fade: true, + } return ( <>
-
-
- Haz clic en el botón para cambiar a español. -
- -
+ + {/* 🔹 Show only Spanish switch if current lang is English */} + {i18n.language === 'en' && ( +
+
+
+ Haz clic en el botón para cambiar el idioma a Español. +
+ +
+
+ )} + { + i18n.language === 'es' && ( +
+
+
+ Haz clic en el botón para cambiar el idioma a Inglés. +
+ +
+
+ ) + } + + {/* 🔹 Show only English switch if current lang is Spanish */} + {i18n.language === 'en' && ( +
+
+
+ Click the button to switch the language to Spanish. +
+ +
+
+ )} + {i18n.language === 'es' && ( +
+
+
+ Click the button to switch the language to English. +
+ +
+
+ )} +
+ {/* 🔹 Main Topbar */}
+ {/* Logo */}
logo
+ {/* Contact Info */}
@@ -67,6 +144,7 @@ const HeaderTopbar = () => {
+ {/* Contact Button */}
diff --git a/next-i18next.config.js b/next-i18next.config.js index a7536ca..fb9dd1a 100644 --- a/next-i18next.config.js +++ b/next-i18next.config.js @@ -1,7 +1,7 @@ module.exports = { i18n: { - defaultLocale: 'es', + defaultLocale: 'en', locales: ['en', 'es'], localeDetection: false, },