2021-06-19 17:37:12 -04:00
|
|
|
import styles from "./Panes.module.scss";
|
2021-07-05 06:23:23 -04:00
|
|
|
import { Text } from "preact-i18n";
|
|
|
|
|
2021-07-05 05:59:48 -04:00
|
|
|
import { dispatch } from "../../../redux";
|
2021-07-05 06:23:23 -04:00
|
|
|
import { connectState } from "../../../redux/connector";
|
|
|
|
|
|
|
|
import {
|
|
|
|
Language,
|
|
|
|
LanguageEntry,
|
|
|
|
Languages as Langs,
|
|
|
|
} from "../../../context/Locale";
|
|
|
|
|
2021-06-22 08:28:03 -04:00
|
|
|
import Emoji from "../../../components/common/Emoji";
|
2021-06-19 17:37:12 -04:00
|
|
|
import Checkbox from "../../../components/ui/Checkbox";
|
2021-07-05 06:23:23 -04:00
|
|
|
import Tip from "../../../components/ui/Tip";
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 05:59:48 -04:00
|
|
|
type Props = {
|
2021-07-05 06:23:23 -04:00
|
|
|
locale: Language;
|
|
|
|
};
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
type Key = [string, LanguageEntry];
|
2021-06-22 11:37:06 -04:00
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
function Entry({ entry: [x, lang], locale }: { entry: Key } & Props) {
|
|
|
|
return (
|
|
|
|
<Checkbox
|
|
|
|
key={x}
|
|
|
|
className={styles.entry}
|
|
|
|
checked={locale === x}
|
|
|
|
onChange={(v) => {
|
|
|
|
if (v) {
|
|
|
|
dispatch({
|
|
|
|
type: "SET_LOCALE",
|
|
|
|
locale: x as Language,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}}>
|
|
|
|
<div className={styles.flag}>
|
|
|
|
<Emoji size={42} emoji={lang.emoji} />
|
|
|
|
</div>
|
|
|
|
<span className={styles.description}>{lang.display}</span>
|
|
|
|
</Checkbox>
|
|
|
|
);
|
2021-06-22 11:37:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function Component(props: Props) {
|
2021-07-05 06:23:23 -04:00
|
|
|
const languages = Object.keys(Langs).map((x) => [
|
|
|
|
x,
|
|
|
|
Langs[x as keyof typeof Langs],
|
|
|
|
]) as Key[];
|
2021-06-22 11:37:06 -04:00
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
return (
|
|
|
|
<div className={styles.languages}>
|
|
|
|
<h3>
|
|
|
|
<Text id="app.settings.pages.language.select" />
|
|
|
|
</h3>
|
|
|
|
<div className={styles.list}>
|
|
|
|
{languages
|
|
|
|
.filter(([, lang]) => !lang.alt)
|
|
|
|
.map(([x, lang]) => (
|
|
|
|
<Entry key={x} entry={[x, lang]} {...props} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<h3>
|
|
|
|
<Text id="app.settings.pages.language.other" />
|
|
|
|
</h3>
|
|
|
|
<div className={styles.list}>
|
|
|
|
{languages
|
|
|
|
.filter(([, lang]) => lang.alt)
|
|
|
|
.map(([x, lang]) => (
|
|
|
|
<Entry key={x} entry={[x, lang]} {...props} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<Tip>
|
|
|
|
<span>
|
|
|
|
<Text id="app.settings.tips.languages.a" />
|
|
|
|
</span>{" "}
|
|
|
|
<a
|
|
|
|
href="https://weblate.insrt.uk/engage/revolt/?utm_source=widget"
|
|
|
|
target="_blank">
|
|
|
|
<Text id="app.settings.tips.languages.b" />
|
|
|
|
</a>
|
|
|
|
</Tip>
|
|
|
|
</div>
|
|
|
|
);
|
2021-06-19 17:37:12 -04:00
|
|
|
}
|
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
export const Languages = connectState(Component, (state) => {
|
|
|
|
return {
|
|
|
|
locale: state.locale,
|
|
|
|
};
|
|
|
|
});
|