Skip to content

Commit 18d2687

Browse files
committed
add i18next and config for i18n
Signed-off-by: Michael Robinson <merobi@gmail.com>
1 parent 0f857c5 commit 18d2687

5 files changed

Lines changed: 78 additions & 5 deletions

File tree

web/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@
5959
"redux": "^4.0.1",
6060
"redux-logger": "^3.0.6",
6161
"redux-saga": "^1.0.2",
62-
"webpack-merge": "^4.2.1"
62+
"webpack-merge": "^4.2.1",
63+
"i18next": "^22.0.6",
64+
"i18next-browser-languagedetector": "^7.0.1",
65+
"react-i18next": "^12.0.0"
6366
},
6467
"devDependencies": {
6568
"@types/classnames": "^2.2.10",

web/src/components/header/Header.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import MqText from '../core/text/MqText'
1010
import NamespaceSelect from '../namespace-select/NamespaceSelect'
1111
import React, { ReactElement } from 'react'
1212
import Search from '../search/Search'
13+
import { useTranslation } from 'react-i18next';
1314

1415
const styles = (theme: Theme) => {
1516
return createStyles({
@@ -40,6 +41,7 @@ const styles = (theme: Theme) => {
4041
type HeaderProps = WithStyles<typeof styles>
4142

4243
const Header = (props: HeaderProps): ReactElement => {
44+
const { t } = useTranslation();
4345
const { classes } = props
4446
return (
4547
<AppBar position='fixed' elevation={0} className={classes.appBar}>
@@ -53,7 +55,7 @@ const Header = (props: HeaderProps): ReactElement => {
5355
<NamespaceSelect />
5456
<Box ml={2}>
5557
<MqText link href={API_DOCS_URL}>
56-
API Docs
58+
{t('header.docs_link')}
5759
</MqText>
5860
</Box>
5961
</Box>

web/src/components/jobs/JobDetailPage.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import MqText from '../core/text/MqText'
2424
import RunInfo from './RunInfo'
2525
import RunStatus from './RunStatus'
2626
import Runs from './Runs'
27+
import { useTranslation } from 'react-i18next';
2728

2829
const styles = ({ spacing }: ITheme) => {
2930
return createStyles({
@@ -52,6 +53,7 @@ const JobDetailPage: FunctionComponent<IProps> = props => {
5253
const handleChange = (event: ChangeEvent, newValue: SetStateAction<number>) => {
5354
setTab(newValue)
5455
}
56+
const { t } = useTranslation();
5557

5658
useEffect(() => {
5759
fetchRuns(job.name, job.namespace)
@@ -82,13 +84,13 @@ const JobDetailPage: FunctionComponent<IProps> = props => {
8284
>
8385
<Box mb={2} display={'flex'} justifyContent={'space-between'} alignItems={'center'}>
8486
<Tabs value={tab} onChange={handleChange} textColor='primary' indicatorColor='primary'>
85-
<Tab label='LATEST RUN' disableRipple={true} />
86-
<Tab label='RUN HISTORY' disableRipple={true} />
87+
<Tab label={t('jobs.latest_tab')} disableRipple={true} />
88+
<Tab label={t('jobs.history_tab')} disableRipple={true} />
8789
</Tabs>
8890
<Box display={'flex'} alignItems={'center'}>
8991
<Box mr={1}>
9092
<Button variant='outlined' color='primary' target={'_blank'} href={job.location}>
91-
Location
93+
{t('jobs.location')}
9294
</Button>
9395
</Box>
9496
<IconButton onClick={() => history.push('/')}>

web/src/i18n.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import i18n from 'i18next';
2+
import { initReactI18next } from 'react-i18next';
3+
// import Backend from 'i18next-http-backend';
4+
import LanguageDetector from 'i18next-browser-languagedetector';
5+
6+
i18n
7+
// .use(Backend)
8+
// detect user language
9+
// learn more: https://github.com/i18next/i18next-browser-languageDetector
10+
.use(LanguageDetector)
11+
// pass the i18n instance to react-i18next.
12+
.use(initReactI18next)
13+
// init i18next
14+
// for all options read: https://www.i18next.com/overview/configuration-options
15+
.init({
16+
debug: true,
17+
fallbackLng: 'en',
18+
interpolation: {
19+
escapeValue: false, // not needed for react as it escapes by default
20+
},
21+
resources: {
22+
en: {
23+
translation: {
24+
// here we will place our translations...
25+
header: {
26+
docs_link: 'API Docs'
27+
},
28+
jobs: {
29+
latest_tab: 'LATEST RUN',
30+
history_tab: 'RUN HISTORY',
31+
location: 'LOCATION'
32+
}
33+
}
34+
},
35+
fr: {
36+
translation: {
37+
header: {
38+
docs_link: 'API Docs'
39+
},
40+
jobs: {
41+
latest_tab: 'DERNIÈRE COURSE',
42+
history_tab: "HISTORIQUE D'EXECUTION",
43+
location: 'EMPLACEMENT'
44+
}
45+
}
46+
},
47+
es: {
48+
translation: {
49+
header: {
50+
docs_link: 'API Docs'
51+
},
52+
jobs: {
53+
latest_tab: 'ÚLTIMA EJECUCIÓN',
54+
history_tab: 'HISTORIAL DE EJECUCIONES',
55+
location: 'UBICACIÓN'
56+
}
57+
}
58+
}
59+
60+
}
61+
});
62+
63+
export default i18n;

web/src/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ import App from './components/App'
55
// fonts
66
import './index.css'
77

8+
// i18n
9+
import './i18n.js';
10+
811
ReactDOM.render(<App />, document.getElementById('root'))

0 commit comments

Comments
 (0)