You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
791 B

  1. import {useRouter} from 'next/router'
  2. import ReactFlagsSelect from 'react-flags-select';
  3. const LanguageSelector = () => {
  4. const router = useRouter();
  5. let localeShort = router.locale.substring(0, 2).toUpperCase();
  6. if (localeShort === "EN") localeShort = "GB";
  7. const selectHandler = e => {
  8. let locale = e.toLowerCase();
  9. if (locale === "gb") locale = "en";
  10. router.push("", "", {locale})
  11. };
  12. return (
  13. <ReactFlagsSelect
  14. onSelect={selectHandler}
  15. countries={
  16. // ["GB", "FR", "ES", "DE", "RU"]
  17. ["GB", "FR"]
  18. }
  19. showOptionLabel={false}
  20. selected={localeShort}
  21. selectedSize={15}
  22. optionsSize={22}
  23. showSelectedLabel={false}
  24. showSecondaryOptionLabel={false}
  25. />
  26. );
  27. };
  28. export default LanguageSelector;