Skip to content

Commit be75a05

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

6 files changed

Lines changed: 218 additions & 3 deletions

File tree

package-lock.json

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

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"dependencies": {
3+
"@types/react": "^18.0.25",
4+
"i18next": "^22.0.6",
5+
"i18next-browser-languagedetector": "^7.0.1",
6+
"react-i18next": "^12.0.0"
7+
}
8+
}

web/src/components/header/Header.tsx

Lines changed: 4 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,8 @@ const Header = (props: HeaderProps): ReactElement => {
5355
<NamespaceSelect />
5456
<Box ml={2}>
5557
<MqText link href={API_DOCS_URL}>
56-
API Docs
58+
{/* API Docs */}
59+
{t('header')}
5760
</MqText>
5861
</Box>
5962
</Box>

web/src/components/jobs/JobDetailPage.tsx

Lines changed: 4 additions & 2 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,8 +84,8 @@ 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('JobTab1')} disableRipple={true} />
88+
<Tab label={t('JobTab2')} disableRipple={true} />
8789
</Tabs>
8890
<Box display={'flex'} alignItems={'center'}>
8991
<Box mr={1}>

web/src/i18n.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import i18n from 'i18next';
2+
import { initReactI18next } from 'react-i18next';
3+
import LanguageDetector from 'i18next-browser-languagedetector';
4+
5+
i18n
6+
// detect user language
7+
// learn more: https://github.com/i18next/i18next-browser-languageDetector
8+
.use(LanguageDetector)
9+
// pass the i18n instance to react-i18next.
10+
.use(initReactI18next)
11+
// init i18next
12+
// for all options read: https://www.i18next.com/overview/configuration-options
13+
.init({
14+
debug: true,
15+
fallbackLng: 'en',
16+
interpolation: {
17+
escapeValue: false, // not needed for react as it escapes by default
18+
},
19+
resources: {
20+
en: {
21+
translation: {
22+
// here we will place our translations...
23+
header: 'API Docs',
24+
JobTab1: 'LATEST RUN',
25+
JobTab2: 'RUN HISTORY'
26+
}
27+
},
28+
fr: {
29+
translation: {
30+
header: 'API Docs',
31+
JobTab1: 'DERNIÈRE COURSE',
32+
JobTab2: "HISTORIQUE D'EXECUTION"
33+
}
34+
},
35+
sp: {
36+
translation: {
37+
header: 'API Docs',
38+
JobTab1: 'ÚLTIMA EJECUCIÓN',
39+
JobTab2: 'HISTORIAL DE EJECUCIONES'
40+
}
41+
}
42+
43+
}
44+
});
45+
46+
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)