mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-12-20 11:32:52 +03:00
43 lines
1.1 KiB
React
43 lines
1.1 KiB
React
|
import { useLingui } from '@lingui/react';
|
||
|
|
||
|
import { activateLang, DEFAULT_LANG, LOCALES } from '../utils/lang';
|
||
|
import localeCode2Text from '../utils/localeCode2Text';
|
||
|
|
||
|
export default function LangSelector() {
|
||
|
const { i18n } = useLingui();
|
||
|
|
||
|
return (
|
||
|
<label class="lang-selector">
|
||
|
🌐{' '}
|
||
|
<select
|
||
|
value={i18n.locale || DEFAULT_LANG}
|
||
|
onChange={(e) => {
|
||
|
localStorage.setItem('lang', e.target.value);
|
||
|
activateLang(e.target.value);
|
||
|
}}
|
||
|
>
|
||
|
{LOCALES.map((lang) => {
|
||
|
if (lang === 'pseudo-LOCALE') {
|
||
|
return (
|
||
|
<>
|
||
|
<hr />
|
||
|
<option value={lang} key={lang}>
|
||
|
Pseudolocalization (test)
|
||
|
</option>
|
||
|
</>
|
||
|
);
|
||
|
}
|
||
|
const common = localeCode2Text(lang);
|
||
|
const native = localeCode2Text({ code: lang, locale: lang });
|
||
|
const same = common === native;
|
||
|
return (
|
||
|
<option value={lang} key={lang}>
|
||
|
{same ? common : `${common} (${native})`}
|
||
|
</option>
|
||
|
);
|
||
|
})}
|
||
|
</select>
|
||
|
</label>
|
||
|
);
|
||
|
}
|