Skip to content

Commit 847bd0a

Browse files
authored
Merge pull request #112 from kube-js/develop
feat: added internalisation
2 parents 4fcaebb + 8005a31 commit 847bd0a

File tree

22 files changed

+2873
-2060
lines changed

22 files changed

+2873
-2060
lines changed

assets/jscpd-badge.svg

Lines changed: 2 additions & 2 deletions
Loading

k8s/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
description: A Helm chart for kube-ts-react-client
33
name: kube-ts-react-client
44
version: 1.0.0
5-
appVersion: 1.5.28
5+
appVersion: 1.6.0
66
home: https://cloud.docker.com/u/kubejs/repository/docker/kubejs/kube-ts-react-client
77
icon: https://avatars2.githubusercontent.com/u/47761918?s=200&v=4
88
sources:

k8s/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ replicaCount: 2
66

77
image:
88
repository: kubejs/kube-ts-react-client
9-
tag: 1.5.28
9+
tag: 1.6.0
1010
pullPolicy: Always
1111
containerPort: 80
1212

package-lock.json

Lines changed: 2635 additions & 1915 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"downshift": "3.4.1",
2020
"formik": "1.5.8",
2121
"history": "4.10.1",
22+
"i18n": "^0.8.4",
23+
"i18next": "^19.0.0",
24+
"i18next-browser-languagedetector": "^4.0.1",
2225
"jscpd": "2.0.16",
2326
"jscpd-badge-reporter": "1.1.3",
2427
"ky": "0.15.0",
@@ -28,8 +31,8 @@
2831
"ramda": "0.26.1",
2932
"react": "16.11.0",
3033
"react-dom": "16.11.0",
31-
"react-intl": "3.4.0",
3234
"react-redux": "7.1.3",
35+
"react-i18next": "^11.1.0",
3336
"react-router": "5.1.2",
3437
"react-router-dom": "5.1.2",
3538
"react-scripts": "2.1.8",
@@ -50,11 +53,11 @@
5053
"@testing-library/react-hooks": "3.2.1",
5154
"@types/flat": "0.0.28",
5255
"@types/jest": "24.0.22",
56+
"@types/i18n": "^0.8.6",
5357
"@types/node": "11.15.2",
5458
"@types/ramda": "0.26.33",
5559
"@types/react": "16.9.11",
5660
"@types/react-dom": "16.9.4",
57-
"@types/react-intl": "3.0.0",
5861
"@types/react-redux": "7.1.5",
5962
"@types/react-router": "5.1.2",
6063
"@types/react-router-dom": "5.1.2",

src/atoms/Autocomplete/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import SearchIcon from '@material-ui/icons/Search';
88
import Downshift from 'downshift';
99
import _isNil from 'ramda/src/isNil';
1010
import React, { useRef, useState } from 'react';
11+
import { useTranslation } from 'react-i18next';
1112
import { useDispatch, useSelector } from 'react-redux';
1213
import { useHistory } from 'react-router-dom';
1314
import { autocompleteRequested } from '../../redux/autocomplete/actionCreators';
@@ -115,6 +116,7 @@ const POPPER_OFFSET = 4;
115116

116117
const Autocomplete = ({ id, type }: Options) => {
117118
const classes = useStyles();
119+
const { t } = useTranslation();
118120

119121
const additionalOptions = autocompleteOptions[type];
120122

@@ -166,7 +168,7 @@ const Autocomplete = ({ id, type }: Options) => {
166168
selectedItem,
167169
}) => {
168170
const { onBlur, onFocus, ...inputProps } = getInputProps({
169-
placeholder: 'Search for anything...',
171+
placeholder: t(`${[type]}.search.placeholder`),
170172
...additionalOptions.inputProps,
171173
});
172174

src/atoms/CourseSection/index.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { withStyles } from '@material-ui/core/styles';
77
import Typography from '@material-ui/core/Typography';
88
import PlayCircleOutlineIcon from '@material-ui/icons/PlayCircleOutline';
99
import React from 'react';
10+
import Section from '../../types/items/Section';
1011

1112
const ExpansionPanel = withStyles({
1213
root: {
@@ -52,12 +53,6 @@ export interface Unit {
5253
readonly title: string;
5354
}
5455

55-
export interface Section {
56-
readonly id: string;
57-
readonly title: string;
58-
readonly units: Unit[];
59-
}
60-
6156
interface Options {
6257
readonly section: Section;
6358
readonly expandedIds: string[];
@@ -90,7 +85,7 @@ const CourseSection = ({ section, expandedIds, onChange }: Options) => (
9085
aria-label="mailbox folders"
9186
>
9287
{section.units.map((unit: Unit, index: number) => (
93-
<ListItem divider={section.units.length - 1 !== index}>
88+
<ListItem key={index} divider={section.units.length - 1 !== index}>
9489
<>
9590
<PlayCircleOutlineIcon style={{marginRight: '1rem'}} />
9691
<ListItemText primary={unit.title}></ListItemText>

src/atoms/CourseSections/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import CourseSection, { Section } from '../CourseSection';
2+
import Section from '../../types/items/Section';
3+
import CourseSection from '../CourseSection';
34

45
interface Options {
56
readonly sections: Section[];
@@ -23,9 +24,11 @@ const CourseSections = ({ sections }: Options) => {
2324
}
2425
};
2526

27+
const sortedSections = sections.sort((x: Section, y: Section) => x.order - y.order);
28+
2629
return (
2730
<div>
28-
{sections.map(section => (
31+
{sortedSections.map(section => (
2932
<CourseSection
3033
key={section.id}
3134
section={section}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import Button from '@material-ui/core/Button';
2+
import ListItemText from '@material-ui/core/ListItemText';
3+
import Menu from '@material-ui/core/Menu';
4+
import MenuItem from '@material-ui/core/MenuItem';
5+
import { withStyles } from '@material-ui/core/styles';
6+
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
7+
import LanguageIcon from '@material-ui/icons/Language';
8+
import { useTranslation } from 'react-i18next';
9+
10+
import React from 'react';
11+
12+
const StyledMenu = withStyles({
13+
paper: {
14+
border: '1px solid #d3d4d5',
15+
},
16+
})((props: any) => (
17+
<Menu
18+
elevation={0}
19+
getContentAnchorEl={null}
20+
anchorOrigin={{
21+
horizontal: 'center',
22+
vertical: 'bottom',
23+
}}
24+
transformOrigin={{
25+
horizontal: 'center',
26+
vertical: 'top',
27+
}}
28+
{...props}
29+
/>
30+
));
31+
32+
const StyledMenuItem = withStyles(theme => ({
33+
root: {
34+
'&:focus': {
35+
'& .MuiListItemIcon-root, & .MuiListItemText-primary': {
36+
color: theme.palette.common.white,
37+
},
38+
backgroundColor: theme.palette.primary.main,
39+
},
40+
},
41+
}))(MenuItem);
42+
43+
const langLabels: {[keyof: string]: string} = {
44+
'en-GB': 'English',
45+
'pl-PL': 'Polski'
46+
}
47+
48+
export default function LanguageDropdown() {
49+
// TODO: refactor component
50+
const [anchorEl, setAnchorEl] = React.useState(null);
51+
52+
const handleClick = (event: any) => {
53+
setAnchorEl(event.currentTarget);
54+
};
55+
56+
const handleClose = () => {
57+
setAnchorEl(null);
58+
};
59+
60+
const { i18n } = useTranslation();
61+
62+
const currentLang = (Array.isArray(i18n.languages)) ? i18n.languages[0] : i18n.languages;
63+
64+
const changeLanguage = (lng: string) => {
65+
i18n.changeLanguage(lng);
66+
setAnchorEl(null);
67+
};
68+
69+
return (
70+
<div style={{display: 'flex', alignItems: 'center'}}>
71+
<Button
72+
aria-controls="customized-menu"
73+
aria-haspopup="true"
74+
variant="contained"
75+
color="primary"
76+
onClick={handleClick}
77+
>
78+
<LanguageIcon style={{marginRight: '5'}} /> {langLabels[currentLang]} <ExpandMoreIcon style={{marginLeft: '5'}} />
79+
</Button>
80+
<StyledMenu
81+
id="customized-menu"
82+
anchorEl={anchorEl}
83+
keepMounted
84+
open={Boolean(anchorEl)}
85+
onClose={handleClose}
86+
>
87+
<StyledMenuItem onClick={() => changeLanguage('en-GB')}>
88+
<ListItemText primary={langLabels['en-GB']} />
89+
</StyledMenuItem>
90+
<StyledMenuItem onClick={() => changeLanguage('pl-PL')}>
91+
<ListItemText primary={langLabels['pl-PL']} />
92+
</StyledMenuItem>
93+
</StyledMenu>
94+
</div>
95+
);
96+
}

src/components/CourseView/index.tsx

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,6 @@ import useStyles from './styles';
1515
export interface Params {
1616
readonly courseSlug: string;
1717
}
18-
19-
// FETCH FROM API
20-
const sections = [
21-
{
22-
id: '1',
23-
title: 'Introduction and setup',
24-
},
25-
{
26-
id: '2',
27-
title: 'Helm basics',
28-
},
29-
{
30-
id: '3',
31-
title: 'Jenkins CI/CD setup',
32-
},
33-
{
34-
id: '4',
35-
title: 'Dockerizing node.js application',
36-
},
37-
{
38-
id: '5',
39-
title: 'Deployment on AWS',
40-
},
41-
].map(section => ({...section, units: [
42-
{
43-
title: 'Introduction and the goal of this course'
44-
},
45-
{
46-
title: 'V8 Under the Hood'
47-
},
48-
{
49-
title: 'The Javascript Core'
50-
},
51-
{
52-
title: 'RESTful APIs and JSON'
53-
}
54-
]}));
55-
5618
const CourseView = ({ match }: RouteComponentProps<Params>) => {
5719
const classes = useStyles();
5820

@@ -76,6 +38,23 @@ const CourseView = ({ match }: RouteComponentProps<Params>) => {
7638
? assetsUrl(course.imageUrl)
7739
: courseImagePlaceholder;
7840
const coursePrice = Number(Math.random() * 10 + 9).toFixed(2);
41+
const sections = course.sections.map(section => ({
42+
...section,
43+
units: [
44+
{
45+
title: 'Introduction and the goal of this course',
46+
},
47+
{
48+
title: 'V8 Under the Hood',
49+
},
50+
{
51+
title: 'The Javascript Core',
52+
},
53+
{
54+
title: 'RESTful APIs and JSON',
55+
},
56+
],
57+
}));
7958

8059
return (
8160
<div className={classes.root}>
@@ -103,18 +82,12 @@ const CourseView = ({ match }: RouteComponentProps<Params>) => {
10382
<Container>
10483
<Grid container spacing={3}>
10584
<Grid item xs={12} sm={9}>
106-
<Paper className={classes.paper}>
107-
{/* <div
108-
dangerouslySetInnerHTML={{
109-
__html: course.description as string,
110-
}}
111-
/> */}
112-
<Typography variant="h3" className={classes.contentHeadline}>
113-
Learning content:
114-
</Typography>
115-
116-
<CourseSections sections={sections} />
117-
</Paper>
85+
86+
<Typography variant="h3" className={classes.contentHeadline}>
87+
Learning content:
88+
</Typography>
89+
90+
<CourseSections sections={sections} />
11891
</Grid>
11992
<Grid item xs={12} sm={3}></Grid>
12093
</Grid>

0 commit comments

Comments
 (0)