Skip to content

Commit ae5d73c

Browse files
Implement Language Select UI #490 (#492)
* translation functionality configured. code review requested * code refactored to use proper event information when updating translations and state in TranslationSelect.tsx * fixed styling which was causing the Temperature component to rest on top of the translationSelect component. With this commit the components are now sitting side by sidde. * chaned spanish translation from Spanish to Español * added new key:value in the en and es library under glossary that handles the values needed for the aria-label language change. added an aria-label html property to the mui Select component used within Translation Select. when the webpage language is english the aria label reads 'Select language' and when the webpage is in spanish the aria-label reads 'Seleccionar idioma'. refactored TranslationSelect to import the i18 module directly rather than it requiring the changeTranslation function as a prop from the Header component. Co-authored-by: Jacob <[email protected]>
1 parent d6b1471 commit ae5d73c

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

packages/common/src/i18n/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export default {
6666
saturday: "Saturday",
6767
},
6868
close: "Close",
69+
selectLanguage: "Select language",
6970
},
7071
hotlines: {
7172
nationalSuicidePreventionLifeline: {

packages/common/src/i18n/es.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export default {
6666
saturday: "Sábado",
6767
},
6868
close: "Final",
69+
selectLanguage: "Seleccionar idioma",
6970
},
7071
hotlines: {
7172
nationalSuicidePreventionLifeline: {

packages/web/src/components/Header.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import MenuDrawer from "./MenuDrawer";
1010
import MenuIcon from "@material-ui/icons/Menu";
1111
import Temperature from "./Temperature";
1212
import Toolbar from "@material-ui/core/Toolbar";
13+
import TranslationSelect from "./TranslationSelect";
1314
import Typography from "@material-ui/core/Typography";
15+
1416
import { useTranslation } from "react-i18next";
1517

1618
const Header = () => {
@@ -29,14 +31,19 @@ const Header = () => {
2931
<MenuIcon />
3032
</IconButton>
3133
</Grid>
32-
<Grid alignItems="center" justify="flex-end" container item>
33-
<Grid item component={Temperature} />
34+
<Grid alignItems="center" justify="flex-start" container item>
3435
<Grid item>
3536
<Link to="/">
3637
<Box component={Logo} height={40} width="auto" />
3738
</Link>
3839
</Grid>
3940
</Grid>
41+
<Grid alignItems="center" justify="flex-end" container item>
42+
<Grid item component={Temperature} xs={6} />
43+
<Grid item xs={6}>
44+
<TranslationSelect />
45+
</Grid>
46+
</Grid>
4047
</Grid>
4148
</Container>
4249
</Toolbar>

packages/web/src/components/ResourceCard.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { TResource } from "@upswyng/types";
1212
import { Theme } from "@material-ui/core/styles/createMuiTheme";
1313
import Typography from "@material-ui/core/Typography";
1414
import { getNextOpenText } from "../utils/schedule";
15-
1615
import makeStyles from "@material-ui/styles/makeStyles";
1716
import { useHistory } from "react-router-dom";
1817
import { useTranslation } from "react-i18next";
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { createStyles, makeStyles } from "@material-ui/core/styles";
2+
import FormControl from "@material-ui/core/FormControl";
3+
import MenuItem from "@material-ui/core/MenuItem";
4+
import React from "react";
5+
import Select from "@material-ui/core/Select";
6+
import { Theme } from "@material-ui/core/styles";
7+
import i18n from "../i18n";
8+
import { useTranslation } from "react-i18next";
9+
10+
const useStyles = makeStyles((theme: Theme) =>
11+
createStyles({
12+
formControl: {
13+
margin: theme.spacing(1),
14+
minWidth: 120,
15+
},
16+
selectEmpty: {
17+
marginTop: theme.spacing(2),
18+
},
19+
})
20+
);
21+
22+
const TranslationSelect = () => {
23+
const { t } = useTranslation("glossary");
24+
const classes = useStyles();
25+
const [translationUsed, setTranslationUsed] = React.useState("en");
26+
27+
const changeTranslation = (translation: string) => {
28+
i18n.changeLanguage(translation);
29+
};
30+
31+
const handleChange = (event: React.ChangeEvent<{ value: unknown }>) => {
32+
const translationLanguage = event.target.value as string;
33+
setTranslationUsed(translationLanguage);
34+
changeTranslation(translationLanguage);
35+
};
36+
37+
return (
38+
<div>
39+
<FormControl className={classes.formControl}>
40+
<Select
41+
value={translationUsed}
42+
onChange={handleChange}
43+
aria-label={t("selectLanguage")}
44+
>
45+
<MenuItem value="en">English</MenuItem>
46+
<MenuItem value="es">Español</MenuItem>
47+
</Select>
48+
</FormControl>
49+
</div>
50+
);
51+
};
52+
53+
export default TranslationSelect;

0 commit comments

Comments
 (0)