diff --git a/package.json b/package.json index 6ee95c5..0ff26ff 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,11 @@ "axios": "^0.21.1", "dotenv": "^10.0.0", "framer-motion": "^4", + "i18next": "^20.3.5", "js-cookie": "^2.2.1", "react": "^17.0.2", "react-dom": "^17.0.2", + "react-i18next": "^11.11.4", "react-icons": "^3.0.0", "react-qr-reader": "^2.2.1", "react-redux": "^7.2.4", diff --git a/src/i18n.js b/src/i18n.js new file mode 100644 index 0000000..671a87c --- /dev/null +++ b/src/i18n.js @@ -0,0 +1,28 @@ +import i18n from "i18next"; +import { initReactI18next } from "react-i18next"; + +import enTranslation from "./locales/en/common.json"; +import msTranslation from "./locales/ms/common.json"; + +const resources = { + en: { + common: enTranslation, + }, + ms: { + common: msTranslation, + } +}; + +i18n + .use(initReactI18next) + .init({ + resources, + lng: "ms", + defaultNS: 'common', + interpolation: { + escapeValue: false + }, + debug:true + }); + + export default i18n; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 96b7d62..1633881 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ import App from './App'; import { store } from './app/store'; import reportWebVitals from './reportWebVitals'; import * as serviceWorker from './serviceWorker'; +import "./i18n" import { Provider } from 'react-redux'; require('dotenv').config(); diff --git a/src/locales/en/common.json b/src/locales/en/common.json new file mode 100644 index 0000000..5edd55c --- /dev/null +++ b/src/locales/en/common.json @@ -0,0 +1,49 @@ +{ + "appTitle": "OurSejahtera Contact Tracing", + + "homeExplanation": "This is your QR code. Show this to others to allow them to confirm a contact, or allow them to create an account!", + "scanButtonLabel": "Scan a QR Code", + + "donateButtonLabel": "Donate!", + "donateButtonParagraph": "Servers require money to run, and apps require labor to develop and maintain. You can show your support by donating what you can. Every cent counts, buy me my next coffee, or help pay for a month of server usage!", + + "logOutButtonLabel": "Log Out!", + + "covidPositiveReportButton": "Report Positive COVID19", + "covidPositiveAlertHeader": "Confirm Tested COVID19 Positive", + "covidPositiveAlertBody": "Please confirm that you have been tested POSITIVE with COVID19. Upon confirmation, this app will inform the people you have come in contact with in the last 7 days.", + + "confirm": "Confirm", + "cancel": "Cancel", + + "errorToastTitle": "Error!", + "defaultErrorToastDescription": "An error has occured.", + "confirmedToastTitle": "Confirmed!", + "confirmingToastTitle": "Confirming", + "confirmingToastDescription": "Hold on while we confirm with our servers.", + "notLoggedInToastDescription": "You are not logged in!", + "failedLoginToastTitle": "Login Failed", + "failedLoginToastDescription": "The wrong credentials were used", + "loggingInToastTitle": "Logging you in", + "loggingInToastDescription": "Hold on, we're logging you in.", + "checkingLockoutToastTitle": "Checking your lockout status...", + "badVerificationToastTitle": "Bad Verification", + "badQRCodeToastTitle": "Bad QR Code", + "contactLoggedToastTitle": "Contact Successfully Logged", + "checkingQRToastTitle": "Hold on, we're checking this QR code.", + + "login": "Login", + + "loginPrivacyNotice": "<0><0>Privacy notes:
Telegram Login allows us to verify your identity, without collecting any of your data. Telegram does NOT give us your phone number. The only piece of information stored on our server is your Telegram ID, this is an internal ID Number Telegram uses that is SEPARATE from your Telegram Username.

All the code for this project is <8>Open Source, that means anyone, including you can audit and verify that your information is being handled securely.", + + "lockout": "Lockout", + "lockoutExplanation": "<0>You have reported that you have been tested <1>POSITIVE with COVID19. This lockout is to remind you to quarantine yourself according to local COVID19 health policies. This lockout will automatically be lifted after 14 days.

<5>Please avoid contact with other people for the duration of this lockout!", + + "showQRCode": "Show my QR Code", + + "contactSavedParagraph": "We have succesfully saved your contact! Stay safe out there, and let others scan your QR code too!", + "returnHomeButtonLabel": "Return home", + + "verifyingParagraph": "We are currently verifying you. Please wait.", + "verifyingErrorParagraph": "An error has occured verifying you. Please try scanning the QR code again?" +} \ No newline at end of file diff --git a/src/locales/ms/common.json b/src/locales/ms/common.json new file mode 100644 index 0000000..992d36f --- /dev/null +++ b/src/locales/ms/common.json @@ -0,0 +1,49 @@ +{ + "appTitle": "OurSejahtera Contact Tracing", + + "homeExplanation": "Inilah kod QR anda. Show this to others to allow them to confirm a contact!", + "scanButtonLabel": "Mengimbas kod QR", + + "donateButtonLabel": "Menderma!", + "donateButtonParagraph": "Servers require money to run, and apps require labor to develop and maintain. You can show your support by donating what you can. Every cent counts, buy me my next coffee, or help pay for a month of server usage!", + + "logOutButtonLabel": "Daftar keluar!", + + "covidPositiveReportButton": "Lapor kes COVID19", + "covidPositiveAlertHeader": "Confirm Tested COVID19 Positive", + "covidPositiveAlertBody": "Please confirm that you have been tested POSITIVE with COVID19. Upon confirmation, this app will inform the people you have come in contact with in the last 7 days.", + + "confirm": "Confirm", + "cancel": "Cancel", + + "errorToastTitle": "Error!", + "defaultErrorToastDescription": "An error has occured.", + "confirmedToastTitle": "Confirmed!", + "confirmingToastTitle": "Confirming", + "confirmingToastDescription": "Hold on while we confirm with our servers.", + "notLoggedInToastDescription": "You are not logged in!", + "failedLoginToastTitle": "Login Failed", + "failedLoginToastDescription": "The wrong credentials were used", + "loggingInToastTitle": "Logging you in", + "loggingInToastDescription": "Hold on, we're logging you in.", + "checkingLockoutToastTitle": "Checking your lockout status...", + "badVerificationToastTitle": "Bad Verification", + "badQRCodeToastTitle": "Bad QR Code", + "contactLoggedToastTitle": "Contact Successfully Logged", + "checkingQRToastTitle": "Hold on, we're checking this QR code.", + + "login": "Login", + + "loginPrivacyNotice": "<0><0>Privacy notes:
Telegram Login allows us to verify your identity, without collecting any of your data. Telegram does NOT give us your phone number. The only piece of information stored on our server is your Telegram ID, this is an internal ID Number Telegram uses that is SEPARATE from your Telegram Username.

All the code for this project is <8>Open Source, that means anyone, including you can audit and verify that your information is being handled securely.", + + "lockout": "Lockout", + "lockoutExplanation": "<0>You have reported that you have been tested <1>POSITIVE with COVID19. This lockout is to remind you to quarantine yourself according to local COVID19 health policies. This lockout will automatically be lifted after 14 days.

<5>Please avoid contact with other people for the duration of this lockout!", + + "showQRCode": "Show my QR Code", + + "contactSavedParagraph": "We have succesfully saved your contact! Stay safe out there, and let others scan your QR code too!", + "returnHomeButtonLabel": "Return home", + + "verifyingParagraph": "We are currently verifying you. Please wait.", + "verifyingErrorParagraph": "An error has occured verifying you. Please try scanning the QR code again?" +} \ No newline at end of file diff --git a/src/screens/HomeScreen.js b/src/screens/HomeScreen.js index adf47d5..6c60708 100644 --- a/src/screens/HomeScreen.js +++ b/src/screens/HomeScreen.js @@ -16,6 +16,7 @@ import { } from '@chakra-ui/react'; import axios from 'axios'; import { Fragment, React, useEffect, useRef, useState } from 'react'; +import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; import { Redirect, useHistory } from 'react-router-dom'; import { authLogout } from '../features/auth/authSlice'; @@ -54,13 +55,14 @@ function ConfirmCOVIDPositiveAlertDialog() { const toast = useToast(); const history = useHistory(); const dispatch = useDispatch(); + const [t] = useTranslation(); const onClose = () => { setOpen(false); }; - const showErrorToast = (errorMessage = 'An error has occured.') => { + const showErrorToast = (errorMessage = t("defaultErrorToastDescription")) => { toast.closeAll(); toast({ - title: 'Error!', + title: t("errorToastTitle"), description: errorMessage, status: 'error', duration: 5000, @@ -68,8 +70,8 @@ function ConfirmCOVIDPositiveAlertDialog() { }; const onConfirm = () => { toast({ - title: 'Confirming', - description: 'Hold on while we confirm with our servers.', + title: t("confirmingToastTitle"), + description: t("confirmingToastDescription"), status: 'info', duration: 10000, }); @@ -86,7 +88,7 @@ function ConfirmCOVIDPositiveAlertDialog() { dispatch(setCovidPositive()); toast.closeAll(); toast({ - title: 'Confirmed!', + title: t("confirmedToastTitle"), status: 'info', duration: 2000, }); @@ -98,7 +100,7 @@ function ConfirmCOVIDPositiveAlertDialog() { console.log(err); try { if (err.response.status === 401) { - showErrorToast('You are not logged in!'); + showErrorToast(t("notLoggedInToastDescription")); history.push('/login'); } else { showErrorToast(); @@ -120,7 +122,7 @@ function ConfirmCOVIDPositiveAlertDialog() { setOpen(true); }} > - Report Positive COVID19 + {t("covidPositiveReportButton")} - Confirm Tested COVID19 Positive + {t("covidPositiveAlertHeader")} - Please confirm that you have been tested POSITIVE with COVID19. - Upon confirmation, this app will inform the people you have come - in contact with in the last 7 days. + {t("covidPositiveAlertBody")} @@ -155,6 +155,7 @@ function ConfirmCOVIDPositiveAlertDialog() { function Home() { const history = useHistory(); const dispatch = useDispatch(); + const [t] = useTranslation(); const handleLogout = () => { dispatch(authLogout()); @@ -198,8 +199,7 @@ function Home() { > - This is your QR code. Show this to others to allow them to confirm a - contact, or allow them to create an account! + {t("homeExplanation")} {process.env.REACT_APP_DONATE_LINK && ( - Servers require money to run, and apps require labor to develop - and maintain. You can show your support by donating what you can. - Every cent counts, buy me my next coffee, or help pay for a month - of server usage! + {t("donateButtonParagraph")} )} @@ -230,7 +227,7 @@ function Home() { diff --git a/src/screens/LockoutScreen.js b/src/screens/LockoutScreen.js index 82bd469..78280c6 100644 --- a/src/screens/LockoutScreen.js +++ b/src/screens/LockoutScreen.js @@ -1,6 +1,7 @@ import { Flex, Heading, Text, useToast } from '@chakra-ui/react'; import axios from 'axios'; import { useEffect } from 'react'; +import { Trans, useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; import { Redirect, useHistory } from 'react-router-dom'; import { authLogout } from '../features/auth/authSlice'; @@ -15,10 +16,11 @@ function Lockout() { const dispatch = useDispatch(); const history = useHistory(); const toast = useToast(); + const [t] = useTranslation(); useEffect(() => { toast({ - title: 'Checking your lockout status...', + title: t("checkingLockoutToastTitle"), status: 'info', duration: 10000, }); @@ -44,14 +46,14 @@ function Lockout() { history.push('/login'); } else { toast({ - title: 'Server Error Occurred', + title: t("defaultErrorToastDescription"), status: 'error', duration: 10000, }); } } catch (e) {} }); - }, [dispatch, history, toast]); + }, [dispatch, history, toast, t]); if (!isAuthenticated) return ; if (!isCovidPositive) return ; @@ -72,7 +74,8 @@ function Lockout() { rounded={6} id="contentFlex" > - Lockout + {t("Lockout")} + You have reported that you have been tested POSITIVE with COVID19. This lockout is to remind you to quarantine yourself @@ -85,6 +88,7 @@ function Lockout() { lockout! + ); diff --git a/src/screens/LoginScreen.js b/src/screens/LoginScreen.js index 56d5f50..a4e5800 100644 --- a/src/screens/LoginScreen.js +++ b/src/screens/LoginScreen.js @@ -1,6 +1,8 @@ import { Divider, Flex, Heading, Link, Text, useToast } from '@chakra-ui/react'; import axios from 'axios'; import { React } from 'react'; +import { useTranslation } from 'react-i18next'; +import { Trans } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; import { Redirect, useHistory } from 'react-router-dom'; import TelegramLoginButton from 'react-telegram-login'; @@ -10,14 +12,15 @@ function Login() { const toast = useToast(); const history = useHistory(); const dispatch = useDispatch(); + const [t] = useTranslation(); const isAuthenticated = useSelector(state => state.auth.isAuthenticated); if (isAuthenticated) return ; const handleTelegramResponse = response => { toast({ - title: 'Logging you in', - description: "Hold on, we're logging you in.", + title: t("loggingInToastTitle"), + description: t("loggingInToastDescription"), status: 'info', duration: 10000, isClosable: false, @@ -45,7 +48,7 @@ function Login() { toast.closeAll(); dispatch(authLogout()); toast({ - title: 'An error occurred', + title: t("defaultErrorToastDescription"), description: response.data.message, status: 'error', duration: 9000, @@ -59,8 +62,8 @@ function Login() { if (err.response.status === 401) { dispatch(authLogout()); toast({ - title: 'Login Failed', - description: 'The wrong credentials were used.', + title: t("failedLoginToastTitle"), + description: t("failedLoginToastDescription"), status: 'error', duration: 9000, isClosable: true, @@ -68,8 +71,8 @@ function Login() { } } else { toast({ - title: 'An error occurred', - description: 'Sorry, an error occurred on our side.', + title: t("errorToastTitle"), + description: t("defaultErrorToastDescription"), status: 'error', duration: 9000, isClosable: true, @@ -95,16 +98,17 @@ function Login() { id="contentFlex" > - OurSejahtera Contact Tracing + {t("appTitle")} - Login + {t("login")} + Privacy notes:
Telegram Login allows us to verify your identity, without collecting @@ -125,6 +129,7 @@ function Login() { , that means anyone, including you can audit and verify that your information is being handled securely.
+
); diff --git a/src/screens/ScannerScreen.js b/src/screens/ScannerScreen.js index 213d3b6..3afcf26 100644 --- a/src/screens/ScannerScreen.js +++ b/src/screens/ScannerScreen.js @@ -1,6 +1,7 @@ import { Button, Divider, Flex, useToast } from '@chakra-ui/react'; import axios from 'axios'; import { useEffect, useState } from 'react'; +import { useTranslation } from 'react-i18next'; import QrReader from 'react-qr-reader'; import { useDispatch, useSelector } from 'react-redux'; import { Redirect, useHistory } from 'react-router-dom'; @@ -11,6 +12,7 @@ function Scanner() { const toast = useToast(); const history = useHistory(); const dispatch = useDispatch(); + const [t] = useTranslation(); const [scanData, setScanData] = useState(null); @@ -32,8 +34,7 @@ function Scanner() { const hash = re.exec(scanData); if (hash) { toast({ - title: 'Checking QR code.', - description: "Hold on, we're checking this QR code.", + title: t("checkingQRToastTitle"), status: 'info', duration: 10000, isClosable: false, @@ -51,14 +52,13 @@ function Scanner() { if (res.data.loggedIn) { toast.closeAll(); toast({ - title: 'Contact Succesfully Logged', + title: t("contactLoggedToastTitle"), status: 'info', duration: 2000, }); } else { toast({ - title: "You're not logged in!", - description: 'Please log in and try again!', + title: t("notLoggedInToastDescription"), status: 'error', duration: 2000, }); @@ -70,7 +70,7 @@ function Scanner() { .catch(e => { toast.closeAll(); toast({ - title: 'Bad Verification', + title: t("badVerificationToastTitle"), status: 'error', duration: 2000, }); @@ -78,14 +78,14 @@ function Scanner() { } else { toast.closeAll(); toast({ - title: 'Bad QR code', + title: t("badQRCodeToastTitle"), status: 'error', duration: 3000, isClosable: true, }); } } - }, [scanData, dispatch, history, toast]); + }, [scanData, dispatch, history, toast, t]); const isAuthenticated = useSelector(state => state.auth.isAuthenticated); const isCovidPositive = useSelector(state => state.covid.isCovidPositive); @@ -135,7 +135,7 @@ function Scanner() { history.push('/home'); }} > - Show my QR Code + {t("showQRCode")} diff --git a/src/screens/SuccessScreen.js b/src/screens/SuccessScreen.js index ec2fa94..0bd4448 100644 --- a/src/screens/SuccessScreen.js +++ b/src/screens/SuccessScreen.js @@ -1,8 +1,10 @@ import { Button, Flex, Heading, Text } from '@chakra-ui/react'; +import { useTranslation } from 'react-i18next'; import { useHistory } from 'react-router-dom'; function Success() { const history = useHistory(); + const [t] = useTranslation(); return ( Success! - We have succesfully saved your contact! Stay safe out there, and let - others scan your QR code too! + {t("contactSavedParagraph")} diff --git a/src/screens/VerifyScreen.js b/src/screens/VerifyScreen.js index aedcedf..719c1bc 100644 --- a/src/screens/VerifyScreen.js +++ b/src/screens/VerifyScreen.js @@ -1,12 +1,14 @@ import { Flex, Text } from '@chakra-ui/react'; import axios from 'axios'; import { useEffect, useState } from 'react'; +import { useTranslation } from 'react-i18next'; import { useHistory } from 'react-router-dom'; function Verify(props) { const verifyID = props.match.params.id; const [verifyError, setVerifyError] = useState(false); const history = useHistory(); + const [t] = useTranslation(); useEffect(() => { if (verifyError) return; @@ -33,12 +35,10 @@ function Verify(props) { }, [verifyError, history, verifyID]); const errorMessage = ( - - An error has occured verifying you. Please try scanning the QR code again? - + {t("verifyingErrorParagraph")} ); const loadingMessage = ( - We are currently verifying you. Please wait. + {t("verifyingParagraph")} ); return ( diff --git a/yarn.lock b/yarn.lock index bd645f5..9a47934 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1091,7 +1091,7 @@ dependencies: regenerator-runtime "^0.13.4" -"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.10.3", "@babel/runtime@^7.12.1", "@babel/runtime@^7.12.13", "@babel/runtime@^7.12.5", "@babel/runtime@^7.13.10", "@babel/runtime@^7.9.2": +"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.10.3", "@babel/runtime@^7.12.0", "@babel/runtime@^7.12.1", "@babel/runtime@^7.12.13", "@babel/runtime@^7.12.5", "@babel/runtime@^7.13.10", "@babel/runtime@^7.14.5", "@babel/runtime@^7.9.2": version "7.14.8" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.14.8.tgz#7119a56f421018852694290b9f9148097391b446" integrity sha512-twj3L8Og5SaCRCErB4x4ajbvBIVV77CGeFglHpeg5WC5FF8TZzBWXtTJ4MqaD9QszLYTtr+IsaAL2rEUevb+eg== @@ -6336,6 +6336,13 @@ html-minifier-terser@^5.0.1: relateurl "^0.2.7" terser "^4.6.3" +html-parse-stringify@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/html-parse-stringify/-/html-parse-stringify-3.0.1.tgz#dfc1017347ce9f77c8141a507f233040c59c55d2" + integrity sha512-KknJ50kTInJ7qIScF3jeaFRpMpE8/lfiTdzf/twXyPBLAGrLRTmkz3AdTnKeh40X8k9L2fdYwEp/42WGXIRGcg== + dependencies: + void-elements "3.1.0" + html-webpack-plugin@4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/html-webpack-plugin/-/html-webpack-plugin-4.5.0.tgz#625097650886b97ea5dae331c320e3238f6c121c" @@ -6443,6 +6450,13 @@ human-signals@^1.1.1: resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3" integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw== +i18next@^20.3.5: + version "20.3.5" + resolved "https://registry.yarnpkg.com/i18next/-/i18next-20.3.5.tgz#14308b79a3f1cafb24fdcd8e182d3673baf1e979" + integrity sha512-//MGeU6n4TencJmCgG+TCrpdgAD/NDEU/KfKQekYbJX6QV7sD/NjWQdVdBi+bkT0snegnSoB7QhjSeatrk3a0w== + dependencies: + "@babel/runtime" "^7.12.0" + iconv-lite@0.4.24: version "0.4.24" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" @@ -9913,6 +9927,14 @@ react-focus-lock@2.5.0: use-callback-ref "^1.2.1" use-sidecar "^1.0.1" +react-i18next@^11.11.4: + version "11.11.4" + resolved "https://registry.yarnpkg.com/react-i18next/-/react-i18next-11.11.4.tgz#f6f9a1c827e7a5271377de2bf14db04cb1c9e5ce" + integrity sha512-ayWFlu8Sc7GAxW1PzMaPtzq+yiozWMxs0P1WeITNVzXAVRhC0Httkzw/IiODBta6seJRBCLrtUeFUSXhAIxlRg== + dependencies: + "@babel/runtime" "^7.14.5" + html-parse-stringify "^3.0.1" + react-icons@^3.0.0: version "3.11.0" resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-3.11.0.tgz#2ca2903dfab8268ca18ebd8cc2e879921ec3b254" @@ -12019,6 +12041,11 @@ vm-browserify@^1.0.1: resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.2.tgz#78641c488b8e6ca91a75f511e7a3b32a86e5dda0" integrity sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ== +void-elements@3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-3.1.0.tgz#614f7fbf8d801f0bb5f0661f5b2f5785750e4f09" + integrity sha1-YU9/v42AHwu18GYfWy9XhXUOTwk= + w3c-hr-time@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.2.tgz#0a89cdf5cc15822df9c360543676963e0cc308cd"