Skip to content

Commit 0eef94e

Browse files
authored
fix: Merge pull request #215 from UniversalDataTool/feature/i18n-2
Internationalization rebased, removed http backend replaced with static backend
2 parents 105cd08 + db6aa45 commit 0eef94e

File tree

31 files changed

+2338
-2180
lines changed

31 files changed

+2338
-2180
lines changed

.storybook/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { configure, addDecorator } from "@storybook/react"
33
import Theme from "../src/components/Theme"
44
import "../src/App.css"
55
import "./storybook.css"
6+
import "../src/i18n"
67

78
export const themeDecorator = (storyFn) => {
89
// TODO wrap w/ theme

package-lock.json

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

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"gh-pages": "npm run build:web && npm run build:vanilla && cp lib/vanilla.js build/vanilla.js && cp ./CNAME ./build/CNAME && gh-pages -d build",
2727
"prettier": "prettier --write \"src/**/*.js\"",
2828
"test:prettier": "prettier --check \"src/**/*.js\"",
29-
"test:lint": "npx eslint src",
29+
"test:lint": "eslint src --max-warnings=0",
3030
"test:integration:dev": "./node_modules/cypress/bin/cypress open",
3131
"test:integration": "./node_modules/cypress/bin/cypress run --env failOnSnapshotDiff=false"
3232
},
@@ -91,6 +91,8 @@
9191
"fast-json-patch": "^3.0.0-1",
9292
"ffmpeg-static": "^4.2.4",
9393
"form-data": "^3.0.0",
94+
"i18next": "^19.4.4",
95+
"i18next-browser-languagedetector": "^4.2.0",
9496
"in-browser-download": "^2.0.0",
9597
"jac-format": "^1.1.3",
9698
"js-md5": "^0.7.3",
@@ -102,6 +104,7 @@
102104
"react-dropzone": "^10.1.8",
103105
"react-github-btn": "^1.2.0",
104106
"react-hotkeys": "^2.0.0",
107+
"react-i18next": "^11.4.0",
105108
"react-icons": "^3.9.0",
106109
"react-image-annotate": "^1.2.7",
107110
"react-scripts": "^3.4.1",

src/App.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react"
1+
import React, { Suspense } from "react"
22
import Theme from "./components/Theme"
33
import LocalStorageApp from "./components/LocalStorageApp"
44
import DesktopApp from "./components/DesktopApp"
@@ -10,22 +10,29 @@ import { LabelHelpProvider } from "./components/LabelHelpView"
1010
import { HotkeyStorageProvider } from "./components/HotkeyStorage"
1111
import "./App.css"
1212

13+
import Loading from "./components/Loading"
14+
15+
// Importing Internalization file
16+
import "./i18n"
17+
1318
export const App = () => {
1419
const electron = useElectron()
1520
return (
16-
<Theme>
17-
<AppConfigProvider>
18-
<AuthProvider>
19-
<LabelHelpProvider>
20-
<ToastProvider>
21-
<HotkeyStorageProvider>
22-
{Boolean(electron) ? <DesktopApp /> : <LocalStorageApp />}
23-
</HotkeyStorageProvider>
24-
</ToastProvider>
25-
</LabelHelpProvider>
26-
</AuthProvider>
27-
</AppConfigProvider>
28-
</Theme>
21+
<Suspense fallback={Loading}>
22+
<Theme>
23+
<AppConfigProvider>
24+
<AuthProvider>
25+
<LabelHelpProvider>
26+
<ToastProvider>
27+
<HotkeyStorageProvider>
28+
{Boolean(electron) ? <DesktopApp /> : <LocalStorageApp />}
29+
</HotkeyStorageProvider>
30+
</ToastProvider>
31+
</LabelHelpProvider>
32+
</AuthProvider>
33+
</AppConfigProvider>
34+
</Theme>
35+
</Suspense>
2936
)
3037
}
3138

src/components/AdvancedOptionsView/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { useAppConfig } from "../AppConfig"
88
import { useHotkeyStorage } from "../HotkeyStorage"
99
import KeyboardShortcutManagerDialog from "../KeyboardShortcutManagerDialog"
1010

11+
import { useTranslation } from "react-i18next"
12+
1113
const Button = styled(MuiButton)({
1214
margin: 8,
1315
})
@@ -19,10 +21,13 @@ export const AdvancedOptionsView = ({ onClickEditJSON, onClearLabelData }) => {
1921
const { hotkeys, changeHotkey, clearHotkeys } = useHotkeyStorage()
2022
const [hotkeyDialogOpen, setHotkeyDialogOpen] = useState(false)
2123

24+
// internalization hook
25+
const { t } = useTranslation()
26+
2227
return (
2328
<Box padding={2}>
2429
<Button onClick={onClickEditJSON} variant="outlined">
25-
Edit JSON
30+
{t("added-json")}
2631
</Button>
2732
<Button
2833
onClick={() => {
@@ -36,7 +41,7 @@ export const AdvancedOptionsView = ({ onClickEditJSON, onClearLabelData }) => {
3641
}}
3742
variant="outlined"
3843
>
39-
Clear All Labels
44+
{t("clear-labels")}
4045
</Button>
4146
<Button
4247
variant="outlined"
@@ -49,7 +54,8 @@ export const AdvancedOptionsView = ({ onClickEditJSON, onClearLabelData }) => {
4954
forceUpdate()
5055
}}
5156
>
52-
{posthog.has_opted_out_capturing() ? "Enable" : "Disable"} Telemetry
57+
{posthog.has_opted_out_capturing() ? "Enable" : "Disable"}{" "}
58+
{t("telemetry")}
5359
</Button>
5460
<Button
5561
variant="outlined"
@@ -64,7 +70,7 @@ export const AdvancedOptionsView = ({ onClickEditJSON, onClearLabelData }) => {
6470
window.location.reload()
6571
}}
6672
>
67-
Custom Collaboration Server
73+
{t("custom-collobration-server")}
6874
</Button>
6975
<Button
7076
variant="outlined"
@@ -75,7 +81,8 @@ export const AdvancedOptionsView = ({ onClickEditJSON, onClearLabelData }) => {
7581
)
7682
}}
7783
>
78-
{fromConfig("labelhelp.disabled") ? "Enable" : "Disable"} Label Help
84+
{fromConfig("labelhelp.disabled") ? "Enable" : "Disable"}{" "}
85+
{t("label-help")}
7986
</Button>
8087
{!fromConfig("labelhelp.disabled") && (
8188
<Button
@@ -90,7 +97,7 @@ export const AdvancedOptionsView = ({ onClickEditJSON, onClearLabelData }) => {
9097
setInConfig("labelhelp.apikey", response)
9198
}}
9299
>
93-
Label Help API Key
100+
{t("label-help-api-key")}
94101
</Button>
95102
)}
96103
<Button

src/components/BrushButton/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import useEventCallback from "use-event-callback"
1111
import memoize from "lodash/memoize"
1212
import getBrushColorPalette from "../../utils/get-brush-color-palette.js"
1313

14+
import { useTranslation } from "react-i18next"
15+
1416
const Container = styled("div")({ position: "relative" })
1517
const BrushCircle = styled("div")(({ color }) => ({
1618
display: "inline",
@@ -66,6 +68,9 @@ export default ({ selectedBrush, onChangeSelectedBrush }) => {
6668
memoize(() => onChangeSelectedBrush(color))
6769
)
6870

71+
// internalization hook
72+
const { t } = useTranslation()
73+
6974
return (
7075
<Container
7176
onMouseEnter={() => changeOpen(true)}
@@ -77,15 +82,15 @@ export default ({ selectedBrush, onChangeSelectedBrush }) => {
7782
/>
7883
</IconButton>
7984
<HeaderPopupBox open={open}>
80-
<h1>Sample Brushes</h1>
85+
<h1>{t("sample-brushes")}</h1>
8186
<StyledButton
8287
selected={selectedBrush === "complete" || selectedBrush === "blue"}
8388
iconcolor={colors.blue}
8489
fullWidth
8590
onClick={handleClick("complete")}
8691
>
8792
<BrushCircle color={colors.blue} />
88-
Complete
93+
{t("complete")}
8994
</StyledButton>
9095
<StyledButton
9196
selected={
@@ -96,7 +101,7 @@ export default ({ selectedBrush, onChangeSelectedBrush }) => {
96101
onClick={handleClick("review")}
97102
>
98103
<BrushCircle color={colors.deepOrange} />
99-
Review
104+
{t("review")}
100105
</StyledButton>
101106
<OtherColorContainers>
102107
<StyledIconButton

src/components/CollaborateButton/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import ExitToAppIcon from "@material-ui/icons/ExitToApp"
1515
import CircularProgress from "@material-ui/core/CircularProgress"
1616
import usePosthog from "../../utils/use-posthog"
1717

18+
import { useTranslation } from "react-i18next"
19+
1820
const Container = styled("div")({ position: "relative", marginLeft: 8 })
1921
const WIDTH = 300
2022
const borderColor = colors.grey[500]
@@ -112,6 +114,9 @@ export default ({
112114
const [userName, changeUserName] = useLocalStorage("userName", "anonymous")
113115
const posthog = usePosthog()
114116

117+
// internalization hook
118+
const { t } = useTranslation()
119+
115120
useEffect(() => {
116121
if (loadingSession) {
117122
setTimeout(() => {
@@ -130,10 +135,10 @@ export default ({
130135
<PeopleIcon />
131136
</IconButton>
132137
<PopupBox className={sessionBoxOpen ? "" : "hidden"}>
133-
<h1>Collaborate</h1>
138+
<h1>{t("collobrate")}</h1>
134139
{!inSession ? (
135140
<>
136-
<h2>Join a Session</h2>
141+
<h2>{"join-a-session"}</h2>
137142
<TextField
138143
variant="outlined"
139144
label="URL to Session"
@@ -185,7 +190,7 @@ export default ({
185190
/>
186191
<ExitButton fullWidth onClick={onLeaveSession}>
187192
<ExitToAppIcon className="icon" />
188-
Leave Session
193+
{t("leave-session")}
189194
</ExitButton>
190195
</>
191196
)}

src/components/Composite/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import KeyboardArrowRightIcon from "@material-ui/icons/KeyboardArrowRight"
1010
import Checkbox from "@material-ui/core/Checkbox"
1111
import Box from "@material-ui/core/Box"
1212

13+
import { useTranslation } from "react-i18next"
14+
1315
const Title = styled("div")({
1416
fontSize: 18,
1517
fontWeight: "bold",
@@ -33,6 +35,8 @@ export const Composite = (props) => {
3335
} = props
3436
const [selectedField, changeSelectedField] = useState()
3537

38+
const { t } = useTranslation()
39+
3640
if (!fields) throw new Error("No fields defined. Try adding a field in Setup")
3741

3842
const sample = props.samples[currentSampleIndex]
@@ -99,7 +103,7 @@ export const Composite = (props) => {
99103
<KeyboardArrowRightIcon
100104
style={{ color: colors.grey[500], marginRight: 16 }}
101105
/>
102-
Next
106+
{t("next")}
103107
<Box flexGrow={1} />
104108
<Box height="42px" />
105109
<KeyboardArrowRightIcon />

src/components/Configure3D/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React from "react"
22
import { styled } from "@material-ui/core/styles"
33
import * as colors from "@material-ui/core/colors"
44

5+
import { useTranslation } from "react-i18next"
6+
57
const ExplanationTextHeader = styled("div")({
68
textAlign: "center",
79
paddingTop: 30,
@@ -19,19 +21,20 @@ const GithubLink = styled("a")({
1921
})
2022

2123
const Configure3D = () => {
24+
const { t } = useTranslation()
25+
2226
return (
2327
<ExplanationTextHeader>
2428
<ExplanationText>
25-
Hey, this isn't currently available, but if you'd like this
26-
functionality please let us know by leaving a thumbs up on{" "}
29+
{t("configure-3d-explanation-text-part-1")}{" "}
2730
<GithubLink
2831
target="_blank"
2932
rel="noopener noreferrer"
3033
href="https://github.com/UniversalDataTool/universal-data-tool/issues/20"
3134
>
3235
this
3336
</GithubLink>{" "}
34-
github issue.
37+
{t("github-issue")}.
3538
</ExplanationText>
3639
</ExplanationTextHeader>
3740
)

src/components/ConfigureComposite/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import Box from "@material-ui/core/Box"
1010
import TextField from "@material-ui/core/TextField"
1111
import { setIn } from "seamless-immutable"
1212

13+
import { useTranslation } from "react-i18next"
14+
1315
const Fields = styled("div")({})
1416
const StyledExpansionPanel = styled(ExpansionPanel)({
1517
marginTop: 16,
@@ -22,6 +24,8 @@ const StyledButton = styled(Button)({
2224
})
2325

2426
export default ({ iface, onChange }) => {
27+
const { t } = useTranslation()
28+
2529
return (
2630
<React.Fragment>
2731
<Fields>
@@ -69,7 +73,7 @@ export default ({ iface, onChange }) => {
6973
})
7074
}}
7175
>
72-
Remove Field
76+
{t("remove-field")}
7377
</Button>
7478
</Box>
7579
</ExpansionPanelDetails>
@@ -92,7 +96,7 @@ export default ({ iface, onChange }) => {
9296
)
9397
}}
9498
>
95-
Add New Field
99+
{t("add-new-field")}
96100
</StyledButton>
97101
</Fields>
98102
</React.Fragment>

0 commit comments

Comments
 (0)