2023-01-14 09:51:46 +01:00
|
|
|
import React, {useCallback, useContext, useState} from 'react';
|
2024-04-05 17:14:36 +02:00
|
|
|
import {Box, Button} from "@mui/material";
|
2023-01-14 09:51:46 +01:00
|
|
|
import {LocaleContext} from "shared/locale";
|
|
|
|
|
2024-04-05 17:14:36 +02:00
|
|
|
/*
|
2023-01-14 09:51:46 +01:00
|
|
|
const useStyles = makeStyles((theme) => ({
|
|
|
|
languageFlag: {
|
|
|
|
margin: theme.spacing(0.2),
|
|
|
|
cursor: "pointer",
|
|
|
|
border: 0,
|
|
|
|
}
|
|
|
|
}));
|
2024-04-05 17:14:36 +02:00
|
|
|
*/
|
2023-01-14 09:51:46 +01:00
|
|
|
|
|
|
|
export default function LanguageSelection(props) {
|
|
|
|
|
|
|
|
const api = props.api;
|
|
|
|
const [languages, setLanguages] = useState(null);
|
|
|
|
const {translate: L, setLanguageByCode} = useContext(LocaleContext);
|
|
|
|
|
|
|
|
const onSetLanguage = useCallback((code) => {
|
|
|
|
setLanguageByCode(api, code).then((res) => {
|
|
|
|
if (!res.success) {
|
|
|
|
alert(res.msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
let flags = [];
|
|
|
|
if (languages === null) {
|
|
|
|
api.getLanguages().then((res) => {
|
|
|
|
if (res.success) {
|
|
|
|
setLanguages(res.languages);
|
|
|
|
} else {
|
|
|
|
setLanguages({});
|
|
|
|
alert(res.msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
for (const language of Object.values(languages)) {
|
|
|
|
let key = `lang-${language.code}`;
|
2024-04-05 17:14:36 +02:00
|
|
|
flags.push(<Button type={"button"} title={language.name} onClick={() => onSetLanguage(language.code)}
|
|
|
|
key={key} >
|
2023-01-14 09:51:46 +01:00
|
|
|
<img alt={key} src={`/img/icons/lang/${language.code}.gif`} />
|
2024-04-05 17:14:36 +02:00
|
|
|
</Button>);
|
2023-01-14 09:51:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return <Box mt={1}>
|
|
|
|
{L("general.language") + ": "} { flags }
|
|
|
|
</Box>
|
|
|
|
}
|