From 3c08280b9f195566336ea4ebbd4d983d2444a75e Mon Sep 17 00:00:00 2001 From: utkarsha-deriv Date: Tue, 31 Oct 2023 17:05:35 +0400 Subject: [PATCH] fix: config for label for langauge switcher --- docusaurus.config.js | 12 +++++++ .../LocaleDropdownNavbarItem/index.tsx | 34 ++++++++++++++----- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/docusaurus.config.js b/docusaurus.config.js index be9eb49b..f6a08eef 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -32,6 +32,18 @@ const config = { es: { label: 'Español', }, + fr: { + label: 'Français', + }, + de: { + label: 'Deutsch', + }, + vi: { + label: 'Tiếng Việt', + }, + th: { + label: 'Thai', + }, }, }, diff --git a/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx b/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx index 9a84d1a7..5e99de48 100644 --- a/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx +++ b/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx @@ -35,15 +35,31 @@ export default function LocaleDropdownNavbarItem({ }; }); - const items = [...dropdownItemsBefore, ...localeItems, ...dropdownItemsAfter]; + const getShortNames = (locale) => { + switch (locale) { + case 'en': + return 'EN'; + case 'es': + return 'ES'; + case 'zh-Hans': + return '简体'; + case 'zh-Hant': + return '繁體'; + case 'fr': + return 'FR'; + case 'de': + return 'DE'; + case 'vi': + return 'VI'; + case 'th': + return 'TH'; + default: + return ''; + } + }; - const dropdownLabel = localeConfigs[currentLocale].label; + const items = [...dropdownItemsBefore, ...localeItems, ...dropdownItemsAfter]; + const dropdownLabel = getShortNames(currentLocale); - return ( - {dropdownLabel === 'English' ? 'EN' : 'ES'}} - items={items} - /> - ); + return {dropdownLabel}} items={items} />; }