diff --git a/nest_frontend/App.js b/nest_frontend/App.js index 47f49bd..3101014 100644 --- a/nest_frontend/App.js +++ b/nest_frontend/App.js @@ -5,6 +5,7 @@ import GlobalTheme from "./components/providers/GlobalTheme" import GlobalServer from "./components/providers/GlobalServer" import GlobalUser from "./components/providers/GlobalUser" import PageSwitcher from "./PageSwitcher" +import GlobalLanguage from "./components/providers/GlobalLanguage" /** @@ -15,16 +16,18 @@ import PageSwitcher from "./PageSwitcher" */ export default function App() { return ( - - - - - - - - - - - + + + + + + + + + + + + + ) } diff --git a/nest_frontend/Localization.js b/nest_frontend/LocalizationStrings.js similarity index 98% rename from nest_frontend/Localization.js rename to nest_frontend/LocalizationStrings.js index 94e7445..dbd83db 100644 --- a/nest_frontend/Localization.js +++ b/nest_frontend/LocalizationStrings.js @@ -1,6 +1,3 @@ -import LocalizedStrings from "react-localization" - - /** * All strings contained in the app should be present in this dict. * @@ -12,7 +9,7 @@ import LocalizedStrings from "react-localization" * "{number} km radius" * ``` */ -export default new LocalizedStrings({ +export default { // 🇮🇹 it: { appName: "N.E.S.T.", @@ -214,5 +211,4 @@ export default new LocalizedStrings({ admin: "Ylläpitäjä", user: "Käyttäjä", } -}) - +} diff --git a/nest_frontend/components/interactive/BoxConditionDatetime.js b/nest_frontend/components/interactive/BoxConditionDatetime.js index 8230864..7645374 100644 --- a/nest_frontend/components/interactive/BoxConditionDatetime.js +++ b/nest_frontend/components/interactive/BoxConditionDatetime.js @@ -1,4 +1,4 @@ -import React, { useState } from "react" +import React, { useContext, useState } from "react" import BoxFull from "../base/BoxFull" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { faClock, faPlus } from "@fortawesome/free-solid-svg-icons" @@ -10,7 +10,7 @@ import useRepositoryEditor from "../../hooks/useRepositoryEditor" import ButtonToggleBeforeAfter from "./ButtonToggleBeforeAfter" import Condition from "../../utils/Condition" import convertToLocalISODate from "../../utils/convertToLocalISODate" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" const INVALID_USER_CHARACTERS = /[^0-9TZ:+-]/g @@ -28,6 +28,7 @@ export default function BoxConditionDatetime({ ...props }) { const [datetime, setDatetime] = useState("") const [ba, setBa] = useState(false) const { addCondition } = useRepositoryEditor() + const {strings} = useContext(ContextLanguage) const onInputChange = event => { let text = event.target.value @@ -54,11 +55,11 @@ export default function BoxConditionDatetime({ ...props }) { - {Localization.searchBy} + {strings.searchBy} - {Localization.byTimePeriod} + {strings.byTimePeriod} } {...props} diff --git a/nest_frontend/components/interactive/BoxConditionHashtag.js b/nest_frontend/components/interactive/BoxConditionHashtag.js index db6aa54..b91cc48 100644 --- a/nest_frontend/components/interactive/BoxConditionHashtag.js +++ b/nest_frontend/components/interactive/BoxConditionHashtag.js @@ -1,4 +1,4 @@ -import React, { useState } from "react" +import React, { useContext, useState } from "react" import BoxFull from "../base/BoxFull" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { faHashtag, faPlus } from "@fortawesome/free-solid-svg-icons" @@ -8,7 +8,7 @@ import Style from "./BoxConditionHashtag.module.css" import ButtonIconOnly from "../base/ButtonIconOnly" import useRepositoryEditor from "../../hooks/useRepositoryEditor" import Condition from "../../utils/Condition" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" // Official hashtag regex from https://stackoverflow.com/a/22490853/4334568 // noinspection RegExpAnonymousGroup,LongLine @@ -26,6 +26,7 @@ const INVALID_HASHTAG_CHARACTERS = /([^a-z0-9_\u00c0-\u00d6\u00d8-\u00f6\u00f8-\ export default function BoxConditionHashtag({ ...props }) { const [hashtag, setHashtag] = useState("") const { addCondition } = useRepositoryEditor() + const {strings} = useContext(ContextLanguage) const onInputChange = event => { let text = event.target.value @@ -45,11 +46,11 @@ export default function BoxConditionHashtag({ ...props }) { - {Localization.searchBy} + {strings.searchBy} - {Localization.byHashtag} + {strings.byHashtag} } {...props} diff --git a/nest_frontend/components/interactive/BoxConditionMap.js b/nest_frontend/components/interactive/BoxConditionMap.js index 763ba37..4103575 100644 --- a/nest_frontend/components/interactive/BoxConditionMap.js +++ b/nest_frontend/components/interactive/BoxConditionMap.js @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect, useState } from "react" +import React, { useCallback, useContext, useEffect, useState } from "react" import BoxFull from "../base/BoxFull" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { faAt, faMapPin, faPlus } from "@fortawesome/free-solid-svg-icons" @@ -7,7 +7,7 @@ import ButtonIconOnly from "../base/ButtonIconOnly" import { MapContainer, TileLayer } from "react-leaflet" import useRepositoryEditor from "../../hooks/useRepositoryEditor" import Condition from "../../utils/Condition" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" const STARTING_POSITION = { lat: 41.89309, lng: 12.48289 } @@ -54,6 +54,7 @@ export default function BoxConditionMap({ ...props }) { const [zoom, setZoom] = useState(STARTING_ZOOM) const [map, setMap] = useState(null) const { addCondition } = useRepositoryEditor() + const {strings} = useContext(ContextLanguage) const onMove = useCallback( () => { @@ -101,11 +102,11 @@ export default function BoxConditionMap({ ...props }) { - {Localization.searchBy} + {strings.searchBy} - {Localization.byZone} + {strings.byZone} } childrenClassName={Style.BoxConditionMapContents} diff --git a/nest_frontend/components/interactive/BoxConditionUser.js b/nest_frontend/components/interactive/BoxConditionUser.js index 5da077f..6b74770 100644 --- a/nest_frontend/components/interactive/BoxConditionUser.js +++ b/nest_frontend/components/interactive/BoxConditionUser.js @@ -1,4 +1,4 @@ -import React, { useState } from "react" +import React, { useContext, useState } from "react" import BoxFull from "../base/BoxFull" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { faAt, faPlus } from "@fortawesome/free-solid-svg-icons" @@ -8,7 +8,7 @@ import Style from "./BoxConditionUser.module.css" import ButtonIconOnly from "../base/ButtonIconOnly" import useRepositoryEditor from "../../hooks/useRepositoryEditor" import Condition from "../../utils/Condition" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" const INVALID_USER_CHARACTERS = /[^a-zA-Z0-9]/g @@ -25,6 +25,7 @@ const INVALID_USER_CHARACTERS = /[^a-zA-Z0-9]/g export default function BoxConditionUser({ ...props }) { const [user, setUser] = useState("") const { addCondition } = useRepositoryEditor() + const {strings} = useContext(ContextLanguage) const onInputChange = event => { let text = event.target.value @@ -44,11 +45,11 @@ export default function BoxConditionUser({ ...props }) { - {Localization.searchBy} + {strings.searchBy} - {Localization.byUser} + {strings.byUser} } {...props} diff --git a/nest_frontend/components/interactive/BoxConditions.js b/nest_frontend/components/interactive/BoxConditions.js index e5458c3..10c2573 100644 --- a/nest_frontend/components/interactive/BoxConditions.js +++ b/nest_frontend/components/interactive/BoxConditions.js @@ -1,8 +1,8 @@ -import React from "react" +import React, { useContext } from "react" import BoxFull from "../base/BoxFull" import ConditionBadge from "./ConditionBadge" import useRepositoryEditor from "../../hooks/useRepositoryEditor" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" /** @@ -14,11 +14,12 @@ import Localization from "../../Localization" */ export default function BoxConditions({ ...props }) { const { conditions } = useRepositoryEditor() + const {strings} = useContext(ContextLanguage) const badges = conditions.map((cond, pos) => ) return ( - + {badges} ) diff --git a/nest_frontend/components/interactive/BoxLoggedIn.js b/nest_frontend/components/interactive/BoxLoggedIn.js index 9094934..15f82de 100644 --- a/nest_frontend/components/interactive/BoxLoggedIn.js +++ b/nest_frontend/components/interactive/BoxLoggedIn.js @@ -7,7 +7,7 @@ import ContextUser from "../../contexts/ContextUser" import { useHistory } from "react-router" import Style from "./BoxLoggedIn.module.css" import CurrentServer from "./CurrentServer" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" /** @@ -20,12 +20,13 @@ import Localization from "../../Localization" export default function BoxLoggedIn({ ...props }) { const { logout } = useContext(ContextUser) const history = useHistory() + const {strings} = useContext(ContextLanguage) return ( - + - {Localization.loggedInOn} {Localization.loggedInAs} . + {strings.loggedInOn} {strings.loggedInAs} . {Localization.logout} + >{strings.logout} diff --git a/nest_frontend/components/interactive/BoxLogin.js b/nest_frontend/components/interactive/BoxLogin.js index 8725066..b2e70d4 100644 --- a/nest_frontend/components/interactive/BoxLogin.js +++ b/nest_frontend/components/interactive/BoxLogin.js @@ -8,7 +8,7 @@ import FormButton from "../base/formparts/FormButton" import ContextUser from "../../contexts/ContextUser" import { useHistory } from "react-router" import FormAlert from "../base/formparts/FormAlert" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" /** @@ -25,6 +25,7 @@ export default function BoxLogin({ ...props }) { const [error, setError] = useState(null) const { login } = useContext(ContextUser) const history = useHistory() + const {strings} = useContext(ContextLanguage) const doLogin = async () => { if(working) { @@ -45,9 +46,9 @@ export default function BoxLogin({ ...props }) { } return ( - + - + - + - {Localization.login} + {strings.login} diff --git a/nest_frontend/components/interactive/BoxRepositoriesActive.js b/nest_frontend/components/interactive/BoxRepositoriesActive.js index 0b58d8c..8cc17fa 100644 --- a/nest_frontend/components/interactive/BoxRepositoriesActive.js +++ b/nest_frontend/components/interactive/BoxRepositoriesActive.js @@ -4,7 +4,7 @@ import { faFolderOpen } from "@fortawesome/free-solid-svg-icons" import ContextUser from "../../contexts/ContextUser" import Loading from "../base/Loading" import BoxFullScrollable from "../base/BoxFullScrollable" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" /** * A {@link BoxFull} listing all the user's active repositories. @@ -25,13 +25,14 @@ export default function BoxRepositoriesActive({ ...props }) { const { user } = useContext(ContextUser) + const {strings} = useContext(ContextLanguage) let contents if(repositories === null) { contents = } else if(repositories.length === 0) { - contents = {Localization.emptyMenu}. + contents = {strings.emptyMenu}. } else { contents = repositories.map(repo => ( @@ -50,7 +51,7 @@ export default function BoxRepositoriesActive({ } return ( - + {contents} ) diff --git a/nest_frontend/components/interactive/BoxRepositoriesArchived.js b/nest_frontend/components/interactive/BoxRepositoriesArchived.js index 0555aa3..9114f69 100644 --- a/nest_frontend/components/interactive/BoxRepositoriesArchived.js +++ b/nest_frontend/components/interactive/BoxRepositoriesArchived.js @@ -4,7 +4,7 @@ import { faFolderOpen } from "@fortawesome/free-solid-svg-icons" import ContextUser from "../../contexts/ContextUser" import Loading from "../base/Loading" import BoxFullScrollable from "../base/BoxFullScrollable" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" /** @@ -26,13 +26,14 @@ export default function BoxRepositoriesArchived({ ...props }) { const { user } = useContext(ContextUser) + const {strings} = useContext(ContextLanguage) let contents if(repositories === null) { contents = } else if(repositories.length === 0) { - contents = {Localization.emptyMenu}. + contents = {strings.emptyMenu}. } else { contents = repositories.map(repo => ( @@ -51,7 +52,7 @@ export default function BoxRepositoriesArchived({ } return ( - + {contents} ) diff --git a/nest_frontend/components/interactive/BoxRepositoryCreate.js b/nest_frontend/components/interactive/BoxRepositoryCreate.js index 09736ba..e24fbf8 100644 --- a/nest_frontend/components/interactive/BoxRepositoryCreate.js +++ b/nest_frontend/components/interactive/BoxRepositoryCreate.js @@ -1,4 +1,4 @@ -import React from "react" +import React, { useContext } from "react" import BoxFull from "../base/BoxFull" import FormLabelled from "../base/FormLabelled" import FormLabel from "../base/formparts/FormLabel" @@ -10,7 +10,7 @@ import useRepositoryEditor from "../../hooks/useRepositoryEditor" import FormAlert from "../base/formparts/FormAlert" import goToOnSuccess from "../../utils/goToOnSuccess" import { useHistory } from "react-router" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" /** @@ -34,16 +34,17 @@ export default function BoxRepositoryCreate({ running, ...props }) { } = useRepositoryEditor() const history = useHistory() + const {strings} = useContext(ContextLanguage) return ( - + { e.preventDefault() save() }} > - + setName(e.target.value)} /> - + setEvaluationMode(0)} checked={evaluationMode === 0} /> - {Localization.filterOR} + {strings.filterOR} @@ -67,7 +68,7 @@ export default function BoxRepositoryCreate({ running, ...props }) { onChange={() => setEvaluationMode(1)} checked={evaluationMode === 1} /> - {Localization.filterAND} + {strings.filterAND} {error ? @@ -84,7 +85,7 @@ export default function BoxRepositoryCreate({ running, ...props }) { onClick={() => revert()} disabled={running} > - {Localization.rollback} + {strings.rollback} goToOnSuccess(save, history, "/repositories")()} disabled={running} > - {Localization.save} + {strings.save} > : @@ -104,7 +105,7 @@ export default function BoxRepositoryCreate({ running, ...props }) { onClick={_ => goToOnSuccess(save, history, "/repositories")()} disabled={running} > - {Localization.createRepo} + {strings.createRepo} } diff --git a/nest_frontend/components/interactive/BoxSetServer.js b/nest_frontend/components/interactive/BoxSetServer.js index 319b525..6dc6973 100644 --- a/nest_frontend/components/interactive/BoxSetServer.js +++ b/nest_frontend/components/interactive/BoxSetServer.js @@ -5,7 +5,7 @@ import FormLabel from "../base/formparts/FormLabel" import InputWithIcon from "../base/InputWithIcon" import { faGlobe } from "@fortawesome/free-solid-svg-icons" import ContextServer from "../../contexts/ContextServer" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" /** @@ -17,11 +17,12 @@ import Localization from "../../Localization" */ export default function BoxSetServer({ ...props }) { const { server, setServer } = useContext(ContextServer) + const {strings} = useContext(ContextLanguage) return ( - + - + { @@ -28,9 +29,9 @@ export default function BoxUserCreate({ createUser, running, ...props }) { ) return ( - + - + setUsername(event.target.value)} /> - + setEmail(event.target.value)} /> - + - {Localization.create} + {strings.create} diff --git a/nest_frontend/components/interactive/BoxUserList.js b/nest_frontend/components/interactive/BoxUserList.js index ff9f8ae..161de0e 100644 --- a/nest_frontend/components/interactive/BoxUserList.js +++ b/nest_frontend/components/interactive/BoxUserList.js @@ -1,11 +1,13 @@ -import React from "react" +import React, { useContext } from "react" import Loading from "../base/Loading" import BoxFullScrollable from "../base/BoxFullScrollable" import SummaryUser from "./SummaryUser" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" export default function BoxUserList({ users, destroyUser, running, ...props }) { + const {strings} = useContext(ContextLanguage) + let contents if(users === null) { contents = @@ -16,7 +18,7 @@ export default function BoxUserList({ users, destroyUser, running, ...props }) { } return ( - + {contents} ) diff --git a/nest_frontend/components/interactive/BoxWordcloud.js b/nest_frontend/components/interactive/BoxWordcloud.js index 2fb0564..6d96b6a 100644 --- a/nest_frontend/components/interactive/BoxWordcloud.js +++ b/nest_frontend/components/interactive/BoxWordcloud.js @@ -1,7 +1,7 @@ -import React from "react" +import React, { useContext } from "react" import BoxFull from "../base/BoxFull" import ReactWordcloud from "@steffo/nest-react-wordcloud" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" /** @@ -13,8 +13,10 @@ import Localization from "../../Localization" * @constructor */ export default function BoxWordcloud({ words, props }) { + const {strings} = useContext(ContextLanguage) + return ( - + { onUpdate(!value) @@ -20,7 +21,7 @@ export default function ButtonToggleBeforeAfter({ onUpdate, className, ...props onClick={onButtonClick} {...props} > - {value ? Localization.timeBefore : Localization.timeAfter} + {value ? strings.timeBefore : strings.timeAfter} ) } diff --git a/nest_frontend/components/interactive/LoggedInUser.js b/nest_frontend/components/interactive/LoggedInUser.js index 9fa19fb..e3559bc 100644 --- a/nest_frontend/components/interactive/LoggedInUser.js +++ b/nest_frontend/components/interactive/LoggedInUser.js @@ -2,7 +2,7 @@ import React, { useContext } from "react" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { faUser } from "@fortawesome/free-solid-svg-icons" import ContextUser from "../../contexts/ContextUser" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" /** @@ -14,11 +14,12 @@ import Localization from "../../Localization" */ export default function LoggedInUser({ ...props }) { const { user } = useContext(ContextUser) + const {strings} = useContext(ContextLanguage) if(!user) { return ( - {Localization.notLoggedIn} + {strings.notLoggedIn} ) } diff --git a/nest_frontend/components/interactive/Logo.js b/nest_frontend/components/interactive/Logo.js index 5fd5d3b..f6256c2 100644 --- a/nest_frontend/components/interactive/Logo.js +++ b/nest_frontend/components/interactive/Logo.js @@ -4,7 +4,7 @@ import LogoDark from "../../media/LogoDark.png" import LogoLight from "../../media/LogoLight.png" import ContextTheme from "../../contexts/ContextTheme" import classNames from "classnames" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" /** @@ -18,9 +18,8 @@ import Localization from "../../Localization" * @constructor */ export default function Logo({ className, ...props }) { - // I have no idea why IntelliJ is complaining about this line - // It's perfectly fine! const { theme } = useContext(ContextTheme) + const {strings} = useContext(ContextLanguage) let logo if(theme === "ThemeDark") { @@ -37,8 +36,8 @@ export default function Logo({ className, ...props }) { ) diff --git a/nest_frontend/components/interactive/SelectLanguage.js b/nest_frontend/components/interactive/SelectLanguage.js index a788f22..6aa3429 100644 --- a/nest_frontend/components/interactive/SelectLanguage.js +++ b/nest_frontend/components/interactive/SelectLanguage.js @@ -1,6 +1,6 @@ -import React, { useState } from "react" +import React, { useContext } from "react" import Select from "../base/Select" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" /** @@ -12,17 +12,10 @@ import Localization from "../../Localization" * @constructor */ export default function SelectLanguage({ ...props }) { - const [_language, _setLanguage] = useState(Localization.getLanguage()) - - const setLanguage = event => { - const language = event.target.value - console.info("Changing language to: ", language) - Localization.setLanguage(language) - _setLanguage(language) - } + const {strings, lang, setLang} = useContext(ContextLanguage) return ( - + setLang(event.target.value)} {...props}> 🇮🇹 Italiano 🇬🇧 English 🇫🇮 Suomi diff --git a/nest_frontend/components/interactive/SelectTheme.js b/nest_frontend/components/interactive/SelectTheme.js index 73b4eb0..37a3607 100644 --- a/nest_frontend/components/interactive/SelectTheme.js +++ b/nest_frontend/components/interactive/SelectTheme.js @@ -1,7 +1,7 @@ import React, { useContext } from "react" import Select from "../base/Select" import ContextTheme from "../../contexts/ContextTheme" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" /** @@ -14,11 +14,12 @@ import Localization from "../../Localization" */ export default function SelectTheme({ ...props }) { const { theme, setTheme } = useContext(ContextTheme) + const {strings} = useContext(ContextLanguage) return ( setTheme(e.target.value)} {...props}> - {Localization.darkMode} - {Localization.lightMode} + {strings.darkMode} + {strings.lightMode} ) } diff --git a/nest_frontend/components/interactive/Sidebar.js b/nest_frontend/components/interactive/Sidebar.js index 58247e7..be94dd8 100644 --- a/nest_frontend/components/interactive/Sidebar.js +++ b/nest_frontend/components/interactive/Sidebar.js @@ -12,7 +12,7 @@ import { faUserCog, } from "@fortawesome/free-solid-svg-icons" import ContextUser from "../../contexts/ContextUser" -import Localization from "../../Localization" +import ContextLanguage from "../../contexts/ContextLanguage" /** @@ -26,6 +26,7 @@ import Localization from "../../Localization" */ export default function Sidebar({ className, ...props }) { const { user } = useContext(ContextUser) + const {strings} = useContext(ContextLanguage) return (