File size: 1,713 Bytes
075a2b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
 * Language Switcher Component
 *
 * Allows users to switch between Japanese and English
 */
import { useTranslation } from 'react-i18next';

type Language = 'ja' | 'en';

interface LanguageOption {
  code: Language;
  label: string;
  flag: string;
}

const languages: LanguageOption[] = [
  { code: 'ja', label: '日本語', flag: '🇯🇵' },
  { code: 'en', label: 'English', flag: '🇬🇧' }
];

export const LanguageSwitcher = () => {
  const { i18n } = useTranslation();

  const changeLanguage = (lang: Language) => {
    i18n.changeLanguage(lang);
    localStorage.setItem('nullai_language', lang);
  };

  const currentLanguage = i18n.language as Language;

  return (
    <div className="language-switcher" style={{
      display: 'flex',
      gap: '8px',
      alignItems: 'center'
    }}>
      {languages.map((lang) => (
        <button
          key={lang.code}
          onClick={() => changeLanguage(lang.code)}
          className={`lang-button ${currentLanguage === lang.code ? 'active' : ''}`}
          style={{
            padding: '6px 12px',
            border: currentLanguage === lang.code ? '2px solid #007bff' : '1px solid #ccc',
            borderRadius: '4px',
            backgroundColor: currentLanguage === lang.code ? '#e7f3ff' : '#fff',
            cursor: 'pointer',
            fontSize: '14px',
            fontWeight: currentLanguage === lang.code ? 'bold' : 'normal',
            display: 'flex',
            alignItems: 'center',
            gap: '4px',
            transition: 'all 0.2s'
          }}
        >
          <span>{lang.flag}</span>
          <span>{lang.label}</span>
        </button>
      ))}
    </div>
  );
};

export default LanguageSwitcher;