summaryrefslogtreecommitdiff
path: root/docs/src/components/Header/LanguageSelect.tsx
blob: 756fe311a8721081feb576c57bc98279b69a6cc2 (plain) (blame)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import type { FunctionalComponent } from 'preact';
import { h } from 'preact';
import './LanguageSelect.css';

const LanguageSelect: FunctionalComponent<{ lang: string }> = ({ lang }) => {
  return (
    <div class="language-select-wrapper">
      <svg
        aria-hidden="true"
        focusable="false"
        role="img"
        xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 88.6 77.3"
        height="1.2em"
        width="1.2em"
      >
        <path
          fill="currentColor"
          d="M61,24.6h7.9l18.7,51.6h-7.7l-5.4-15.5H54.3l-5.6,15.5h-7.2L61,24.6z M72.6,55l-8-22.8L56.3,55H72.6z"
        />
        <path
          fill="currentColor"
          d="M53.6,60.6c-10-4-16-9-22-14c0,0,1.3,1.3,0,0c-6,5-20,13-20,13l-4-6c8-5,10-6,19-13c-2.1-1.9-12-13-13-19h8          c4,9,10,14,10,14c10-8,10-19,10-19h8c0,0-1,13-12,24l0,0c5,5,10,9,19,13L53.6,60.6z M1.6,16.6h56v-8h-23v-7h-9v7h-24V16.6z"
        />
      </svg>
      <select
        class="language-select"
        value={lang}
        aria-label="Select language"
        onChange={(e) => {
          const newLang = e.target.value;
          if (newLang === 'en') {
            window.location.pathname = `/getting-started`;
          } else {
            window.location.pathname = `/${newLang}/getting-started`;
          }
          // TODO: Preserve the current page, if it exists:
          // const oldPathname = window.location.pathname;
          // const oldPathnameParts = oldPathname.split('/');
          // oldPathnameParts.shift();
          // if (/^[a-z]{2}$/.test(oldPathnameParts[0])) {
          //   oldPathnameParts.shift();
          // }
          // if (newLang !== 'en') {
          //   oldPathnameParts.unshift(newLang);
          // }
          // window.location.pathname = '/' + oldPathnameParts.join('/');
        }}
      >
        <option value="en">
          <span>English</span>
        </option>
        <option value="de">
          <span>Deutsch</span>
        </option>
        <option value="nl">
          <span>Nederlands</span>
        </option>
        <option value="pt-br">
          <span>Português do Brasil</span>
        </option>
        <option value="fi">
          <span>Suomi</span>
        </option>
        <option value="es">
          <span>Español</span>
        </option>
        <option value="zh-CN">
          <span>简体中文</span>
        </option>
        <option value="zh-TW">
          <span>正體中文</span>
        </option>
        <option value="bg">
          <span>Български</span>
        </option>
        <option value="fr">
          <span>Français</span>
        </option>
        <option value="bn">
          <span>বাংলা</span>
        </option>
        <option value="kr">
          <span>한국어</span>
        </option>
        <option value="ar">
          <span>العربية</span>
        </option>
        <option value="da">
          <span>Dansk</span>
        </option>
        <option value="ja">
          <span>日本語</span>
        </option>
        <option value="ru">
          <span>Русский</span>
        </option>
      </select>
    </div>
  );
};

export default LanguageSelect;
r>2022-02-24[ci] yarn formatGravatar natemoo-re 2-24/+24 2022-02-24[ci] release (#2641)astro@0.23.1@astrojs/markdown-remark@0.6.2Gravatar github-actions[bot] 38-90/+81 2022-02-24ensure utf8 encoding when serving html (#2654)Gravatar Fred K. Schott 3-4/+9 2022-02-24fix(core): Issue #2625. error with process.env.LANG larger than 5 (#2645)Gravatar Javier Cortés 2-1/+6 2022-02-24[ci] update lockfile (#2646)Gravatar Fred K. Schott 1-130/+124 2022-02-24chore: upgrade compiler (#2653)Gravatar Nate Moore 3-11/+11 2022-02-24[ci] yarn formatGravatar natemoo-re 2-5/+5 2022-02-24Add fine-grained HMR support (#2649)Gravatar Nate Moore 7-36/+37 2022-02-24[ci] collect statsGravatar FredKSchott 1-0/+1 2022-02-23Fixed incorrect types and imports (#2630)Gravatar Juan Martín Seery 27-35/+37 2022-02-23Add sass dev dep to blog-multiple-authors example (#2643)Gravatar Joel Kuzmarski 1-1/+2 2022-02-23Fix(component): align starting position in Markdown slot (#2631)Gravatar Shinobu Hayashi 4-6/+61 2022-02-23[ci] yarn formatGravatar matthewp 1-1/+1 2022-02-23Run all smoke tests with the static build (#2609)Gravatar Matthew Phillips 2-26/+32 2022-02-23[ci] collect statsGravatar FredKSchott 1-0/+1 2022-02-22[ci] update lockfile (#2624)Gravatar Fred K. Schott 1-171/+201 2022-02-22Fixed shiki import to work with "type": "module" (#2628)Gravatar Juan Martín Seery 3-5/+13