LangSwitch.tsx 953 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { detectLang } from '../messages/index.js';
  2. interface LangSwitchProps {
  3. /** Override target paths. [enTarget, ruTarget]. Default: ['/', '/ru'] */
  4. targets?: [string, string];
  5. }
  6. export function LangSwitch({ targets }: LangSwitchProps) {
  7. const lang = detectLang();
  8. const [enTarget, ruTarget] = targets ?? ['/', '/ru'];
  9. const TO: Record<string, { label: string; href: string }> = {
  10. en: { label: 'en', href: ruTarget },
  11. ru: { label: 'ru', href: enTarget },
  12. };
  13. const { label, href } = TO[lang];
  14. return (
  15. <a
  16. href={href}
  17. style={{
  18. position: 'absolute',
  19. top: '8px',
  20. right: '12px',
  21. fontSize: '0.7rem',
  22. fontWeight: 'bold',
  23. color: '#787c7e',
  24. textDecoration: 'none',
  25. border: 'none',
  26. background: 'none',
  27. cursor: 'pointer',
  28. fontFamily: 'monospace',
  29. textTransform: 'uppercase',
  30. }}
  31. >
  32. {label}
  33. </a>
  34. );
  35. }