Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
fix: config for label for langauge switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarsha-deriv committed Oct 31, 2023
1 parent eb7545c commit 3c08280
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
12 changes: 12 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
},

Expand Down
34 changes: 25 additions & 9 deletions src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<DropdownNavbarItem
{...props}
label={<>{dropdownLabel === 'English' ? 'EN' : 'ES'}</>}
items={items}
/>
);
return <DropdownNavbarItem {...props} label={<>{dropdownLabel}</>} items={items} />;
}

0 comments on commit 3c08280

Please sign in to comment.