LanguageSelector.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React from 'react';
  16. import { Button, Dropdown } from '@douyinfe/semi-ui';
  17. import { Languages } from 'lucide-react';
  18. import { CN, GB, FR } from 'country-flag-icons/react/3x2';
  19. const LanguageSelector = ({ currentLang, onLanguageChange, t }) => {
  20. return (
  21. <Dropdown
  22. position='bottomRight'
  23. render={
  24. <Dropdown.Menu className='!bg-semi-color-bg-overlay !border-semi-color-border !shadow-lg !rounded-lg dark:!bg-gray-700 dark:!border-gray-600'>
  25. <Dropdown.Item
  26. onClick={() => onLanguageChange('zh')}
  27. className={`!flex !items-center !gap-2 !px-3 !py-1.5 !text-sm !text-semi-color-text-0 dark:!text-gray-200 ${currentLang === 'zh' ? '!bg-semi-color-primary-light-default dark:!bg-blue-600 !font-semibold' : 'hover:!bg-semi-color-fill-1 dark:hover:!bg-gray-600'}`}
  28. >
  29. <CN title='中文' className='!w-5 !h-auto' />
  30. <span>中文</span>
  31. </Dropdown.Item>
  32. <Dropdown.Item
  33. onClick={() => onLanguageChange('en')}
  34. className={`!flex !items-center !gap-2 !px-3 !py-1.5 !text-sm !text-semi-color-text-0 dark:!text-gray-200 ${currentLang === 'en' ? '!bg-semi-color-primary-light-default dark:!bg-blue-600 !font-semibold' : 'hover:!bg-semi-color-fill-1 dark:hover:!bg-gray-600'}`}
  35. >
  36. <GB title='English' className='!w-5 !h-auto' />
  37. <span>English</span>
  38. </Dropdown.Item>
  39. <Dropdown.Item
  40. onClick={() => onLanguageChange('fr')}
  41. className={`!flex !items-center !gap-2 !px-3 !py-1.5 !text-sm !text-semi-color-text-0 dark:!text-gray-200 ${currentLang === 'fr' ? '!bg-semi-color-primary-light-default dark:!bg-blue-600 !font-semibold' : 'hover:!bg-semi-color-fill-1 dark:hover:!bg-gray-600'}`}
  42. >
  43. <FR title='Français' className='!w-5 !h-auto' />
  44. <span>Français</span>
  45. </Dropdown.Item>
  46. </Dropdown.Menu>
  47. }
  48. >
  49. <Button
  50. icon={<Languages size={18} />}
  51. aria-label={t('common.changeLanguage')}
  52. theme='borderless'
  53. type='tertiary'
  54. className='!p-1.5 !text-current focus:!bg-semi-color-fill-1 dark:focus:!bg-gray-700 !rounded-full !bg-semi-color-fill-0 dark:!bg-semi-color-fill-1 hover:!bg-semi-color-fill-1 dark:hover:!bg-semi-color-fill-2'
  55. />
  56. </Dropdown>
  57. );
  58. };
  59. export default LanguageSelector;