Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Integrated translations into Auth pages

Blue Mouse00b865ff4456
diff --git a/src/i18n/en.json b/src/i18n/en.json
index b60e965ad..e21488dda 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -71,6 +71,52 @@
"custSupport": "Could not find the answer you’re looking for? Reach out to our <mail>customer support</mail> team.",
"whyUs": "Why us"
},
+ "auth": {
+ "recovery": {
+ "title": "Account recovery",
+ "save": "Save new password",
+ "newPassword": "Your new password",
+ "updated": "Your password has been updated"
+ },
+ "forgot": {
+ "sent": "A password reset e-mail has been sent to the specified address",
+ "reset": "Reset password"
+ },
+ "signin": {
+ "title": "Sign in to your account",
+ "forgot": "Forgot password?",
+ "button": "Sign in"
+ },
+ "signup": {
+ "button": "Sign up",
+ "tos": "I do accept <tos>Terms and Conditions</tos> and the <pp>Privacy Policy</pp>.",
+ "email": "Email address",
+ "create": "Create your account"
+ },
+ "verification": {
+ "success": "Your email has been successfully verified!"
+ },
+ "common": {
+ "signinInstead": "Sign in instead",
+ "signupInstead": "Sign up instead",
+ "password": "Password",
+ "noRemember": "Don't remember me.",
+ "repeat": "Repeat password",
+ "hint": "Longer than {{amount}} chars",
+ "xCharsError": "The password has to consist of at least {{amount}} characters.",
+ "noMatchError": "Passwords have to match.",
+ "badEmailError": "Please provide a valid email.",
+ "tosError": "You have to accept our TOS and privacy policy in order to use our services.",
+ "email": "Email",
+ "signin": "Sign in"
+ }
+ },
+ "titles": {
+ "recovery": "Account recovery",
+ "signin": "Sign in",
+ "signup": "Sign up",
+ "verification": "Email verification"
+ },
"footer": {
"slogan": "The best apps need the best services.",
"description": "Swetrix is a powerful analytics platform that respects user privacy.",
diff --git a/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx b/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
index 82fde42e1..20336c83a 100644
--- a/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
+++ b/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
@@ -1,5 +1,6 @@
import React, { useState, useEffect, memo } from 'react'
import { Link, useHistory, useParams } from 'react-router-dom'
+import { useTranslation } from 'react-i18next'
import { createNewPassword } from 'api'
import { notAuthenticated } from '../../../hoc/protected'
@@ -7,11 +8,12 @@ import Title from 'components/Title'
import routes from 'routes'
import Input from 'ui/Input'
import Button from 'ui/Button'
-import { isValidPassword } from 'utils/validator'
+import { isValidPassword, MIN_PASSWORD_CHARS } from 'utils/validator'
const CreateNewPassword = ({
createNewPasswordFailed, newPassword,
}) => {
+ const { t } = useTranslation('common')
const history = useHistory()
const { id } = useParams()
const [form, setForm] = useState({
@@ -34,7 +36,7 @@ const CreateNewPassword = ({
const { password } = data
await createNewPassword(id, password)
- newPassword('Your password has been updated')
+ newPassword(t('auth.recovery.updated'))
history.push(routes.signin)
} catch (e) {
createNewPasswordFailed(e.toString())
@@ -68,11 +70,11 @@ const CreateNewPassword = ({
const allErrors = {}
if (!isValidPassword(form.password)) {
- allErrors.password = 'The password has to consist of at least 8 characters.'
+ allErrors.password = t('auth.common.xCharsError', { amount: MIN_PASSWORD_CHARS })
}
if (form.password !== form.repeat || form.repeat === '') {
- allErrors.repeat = 'Passwords have to match.'
+ allErrors.repeat = t('auth.common.noMatchError')
}
const valid = Object.keys(allErrors).length === 0
@@ -82,20 +84,20 @@ const CreateNewPassword = ({
}
return (
- <Title title='Account recovery'>
+ <Title title={t('titles.recovery')}>
<div className='min-h-page bg-gray-50 flex flex-col py-6 px-4 sm:px-6 lg:px-8'>
<form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
<h2 className='mt-2 text-3xl font-extrabold text-gray-900'>
- Account recovery
- </h2>
+ {t('auth.recovery.title')}
+ </h2>
<Input
name='password'
id='password'
type='password'
- label='Your new password'
- hint='Longer than 8 chars'
+ label={t('auth.recovery.newPassword')}
+ hint={t('auth.common.hint', { amount: MIN_PASSWORD_CHARS })}
value={form.password}
- placeholder='Password'
+ placeholder={t('auth.common.password')}
className='mt-4'
onChange={handleInput}
error={beenSubmitted && errors.password}
@@ -104,19 +106,19 @@ const CreateNewPassword = ({
name='repeat'
id='repeat'
type='password'
- label='Repeat password'
+ label={t('auth.common.repeat')}
value={form.password}
- placeholder='Password'
+ placeholder={t('auth.common.password')}
className='mt-4'
onChange={handleInput}
error={beenSubmitted && errors.repeat}
/>
<div className='flex justify-between mt-3'>
<Link to={routes.signin} className='underline text-blue-600 hover:text-indigo-800'>
- Sign in instead
+ {t('auth.common.signinInstead')}
</Link>
<Button type='submit' loading={isLoading} primary large>
- Save new password
+ {t('auth.recovery.save')}
</Button>
</div>
</form>
diff --git a/src/pages/Auth/ForgotPassword/ForgotPassword.jsx b/src/pages/Auth/ForgotPassword/ForgotPassword.jsx
index eb29b6544..2b03b9218 100644
--- a/src/pages/Auth/ForgotPassword/ForgotPassword.jsx
+++ b/src/pages/Auth/ForgotPassword/ForgotPassword.jsx
@@ -1,5 +1,6 @@
import React, { useState, useEffect, memo } from 'react'
import { Link, useHistory } from 'react-router-dom'
+import { useTranslation } from 'react-i18next'
import { forgotPassword } from 'api'
import Title from 'components/Title'
@@ -12,6 +13,7 @@ import { isValidEmail } from 'utils/validator'
const ForgotPassword = ({
createNewPasswordFailed, newPassword,
}) => {
+ const { t } = useTranslation('common')
const history = useHistory()
const [form, setForm] = useState({
email: '',
@@ -32,7 +34,7 @@ const ForgotPassword = ({
try {
await forgotPassword(data)
- newPassword('A password reset e-mail has been sent to the specified address')
+ newPassword(t('auth.forgot.sent'))
history.push(routes.main)
} catch (e) {
createNewPasswordFailed(e.toString())
@@ -66,7 +68,7 @@ const ForgotPassword = ({
const allErrors = {}
if (!isValidEmail(form.email)) {
- allErrors.email = 'Please provide a valid email.'
+ allErrors.email = t('auth.common.badEmailError')
}
const valid = Object.keys(allErrors).length === 0
@@ -76,17 +78,17 @@ const ForgotPassword = ({
}
return (
- <Title title='Account recovery'>
+ <Title title={t('titles.recovery')}>
<div className='min-h-page bg-gray-50 flex flex-col py-6 px-4 sm:px-6 lg:px-8'>
<form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
<h2 className='mt-2 text-3xl font-extrabold text-gray-900'>
- Account recovery
- </h2>
+ {t('titles.recovery')}
+ </h2>
<Input
name='email'
id='email'
type='email'
- label='Email'
+ label={t('auth.common.email')}
value={form.email}
placeholder='[email protected]'
className='mt-4'
@@ -95,10 +97,10 @@ const ForgotPassword = ({
/>
<div className='flex justify-between mt-3'>
<Link to={routes.signin} className='mt-1 underline text-blue-600 hover:text-indigo-800'>
- Sign in
+ {t('auth.common.signin')}
</Link>
<Button type='submit' loading={isLoading} primary large>
- Reset password
+ {t('auth.forgot.reset')}
</Button>
</div>
</form>
diff --git a/src/pages/Auth/Signin/Signin.jsx b/src/pages/Auth/Signin/Signin.jsx
index 97483cb70..372181c7c 100644
--- a/src/pages/Auth/Signin/Signin.jsx
+++ b/src/pages/Auth/Signin/Signin.jsx
@@ -1,6 +1,7 @@
import React, { useState, useEffect, memo } from 'react'
import { Link } from 'react-router-dom'
import PropTypes from 'prop-types'
+import { useTranslation } from 'react-i18next'
import Title from 'components/Title'
import { notAuthenticated } from '../../../hoc/protected'
@@ -8,9 +9,12 @@ import routes from 'routes'
import Input from 'ui/Input'
import Button from 'ui/Button'
import Checkbox from 'ui/Checkbox'
-import { isValidEmail, isValidPassword } from 'utils/validator'
+import {
+ isValidEmail, isValidPassword, MIN_PASSWORD_CHARS,
+} from 'utils/validator'
const Signin = ({ login }) => {
+ const { t } = useTranslation('common')
const [form, setForm] = useState({
email: '',
password: '',
@@ -58,11 +62,11 @@ const Signin = ({ login }) => {
const allErrors = {}
if (!isValidEmail(form.email)) {
- allErrors.email = 'Please provide a valid email.'
+ allErrors.email = t('auth.common.badEmailError')
}
if (!isValidPassword(form.password)) {
- allErrors.password = 'The password has to consist of at least 8 characters.'
+ allErrors.password = t('auth.common.xCharsError', { amount: MIN_PASSWORD_CHARS })
}
const valid = Object.keys(allErrors).length === 0
@@ -72,17 +76,17 @@ const Signin = ({ login }) => {
}
return (
- <Title title='Sign in'>
+ <Title title={t('titles.signin')}>
<div className='min-h-page bg-gray-50 flex flex-col py-6 px-4 sm:px-6 lg:px-8'>
<form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
<h2 className='mt-2 text-3xl font-extrabold text-gray-900'>
- Sign in to your account
+ {t('auth.signin.title')}
</h2>
<Input
name='email'
id='email'
type='email'
- label='Email'
+ label={t('auth.common.email')}
value={form.email}
placeholder='[email protected]'
className='mt-4'
@@ -93,10 +97,10 @@ const Signin = ({ login }) => {
name='password'
id='password'
type='password'
- label='Password'
- hint='Longer than 8 chars'
+ label={t('auth.common.password')}
+ hint={t('auth.common.hint', { amount: MIN_PASSWORD_CHARS })}
value={form.password}
- placeholder='Password'
+ placeholder={t('auth.common.password')}
className='mt-4'
onChange={handleInput}
error={beenSubmitted && errors.password}
@@ -107,20 +111,20 @@ const Signin = ({ login }) => {
name='keep_signedin'
id='keep_signedin'
className='mt-4'
- label={'Don\'t remember me.'}
+ label={t('auth.common.noRemember')}
/>
<div className='flex justify-between mt-3'>
<div className='pt-1'>
<Link to={routes.reset_password} className='underline text-blue-600 hover:text-indigo-800'>
- Forgot password?
+ {t('auth.signin.forgot')}
</Link>
<span>&nbsp;|&nbsp;</span>
<Link to={routes.signup} className='underline text-blue-600 hover:text-indigo-800'>
- Sign up instead
+ {t('auth.common.signupInstead')}
</Link>
</div>
<Button type='submit' loading={isLoading} primary large>
- Sign in
+ {t('auth.signin.button')}
</Button>
</div>
</form>
diff --git a/src/pages/Auth/Signup/BasicSignup.jsx b/src/pages/Auth/Signup/BasicSignup.jsx
index cefa66860..4f9b20f4d 100644
--- a/src/pages/Auth/Signup/BasicSignup.jsx
+++ b/src/pages/Auth/Signup/BasicSignup.jsx
@@ -1,12 +1,16 @@
import React, { memo, useState, useEffect } from 'react'
import { useDispatch } from 'react-redux'
import { authActions } from 'redux/actions/auth'
+import { useTranslation } from 'react-i18next'
import Input from 'ui/Input'
import Button from 'ui/Button'
-import { isValidEmail, isValidPassword } from 'utils/validator'
+import {
+ isValidEmail, isValidPassword, MIN_PASSWORD_CHARS,
+} from 'utils/validator'
const BasicSignup = () => {
+ const { t } = useTranslation('common')
const dispatch = useDispatch()
const [form, setForm] = useState({
email: '',
@@ -56,15 +60,15 @@ const BasicSignup = () => {
const allErrors = {}
if (!isValidEmail(form.email)) {
- allErrors.email = 'Please provide a valid email.'
+ allErrors.email = t('auth.common.badEmailError')
}
if (!isValidPassword(form.password)) {
- allErrors.password = 'The password has to consist of at least 8 characters.'
+ allErrors.password = t('auth.common.xCharsError', { amount: MIN_PASSWORD_CHARS })
}
if (form.password !== form.repeat || form.repeat === '') {
- allErrors.repeat = 'Passwords have to match.'
+ allErrors.repeat = t('auth.common.noMatchError')
}
const valid = Object.keys(allErrors).length === 0
@@ -80,7 +84,7 @@ const BasicSignup = () => {
id='email'
type='email'
value={form.email}
- placeholder='Email address'
+ placeholder={t('auth.signup.email')}
onChange={handleInput}
error={beenSubmitted && errors.email}
/>
@@ -89,7 +93,7 @@ const BasicSignup = () => {
id='password'
type='password'
value={form.password}
- placeholder='Password'
+ placeholder={t('auth.common.password')}
className='mt-4'
onChange={handleInput}
error={beenSubmitted && errors.password}
@@ -99,13 +103,13 @@ const BasicSignup = () => {
id='repeat'
type='password'
value={form.repeat}
- placeholder='Repeat password'
+ placeholder={t('auth.common.repeat')}
className='mt-4'
onChange={handleInput}
error={beenSubmitted && errors.repeat}
/>
<Button className='w-full flex justify-center' type='submit' loading={isLoading} primary large>
- Create your account
+ {t('auth.signup.create')}
</Button>
</form>
)
diff --git a/src/pages/Auth/Signup/Signup.jsx b/src/pages/Auth/Signup/Signup.jsx
index ad01813aa..d831765f8 100644
--- a/src/pages/Auth/Signup/Signup.jsx
+++ b/src/pages/Auth/Signup/Signup.jsx
@@ -1,6 +1,7 @@
import React, { useState, useEffect, memo } from 'react'
import { Link } from 'react-router-dom'
import PropTypes from 'prop-types'
+import { useTranslation, Trans } from 'react-i18next'
import Title from 'components/Title'
import { notAuthenticated } from '../../../hoc/protected'
@@ -8,9 +9,12 @@ import routes from 'routes'
import Input from 'ui/Input'
import Checkbox from 'ui/Checkbox'
import Button from 'ui/Button'
-import { isValidEmail, isValidPassword } from 'utils/validator'
+import {
+ isValidEmail, isValidPassword, MIN_PASSWORD_CHARS,
+} from 'utils/validator'
const Signup = ({ signup }) => {
+ const { t } = useTranslation('common')
const [form, setForm] = useState({
email: '',
password: '',
@@ -60,19 +64,19 @@ const Signup = ({ signup }) => {
const allErrors = {}
if (!isValidEmail(form.email)) {
- allErrors.email = 'Please provide a valid email.'
+ allErrors.email = t('auth.common.badEmailError')
}
if (!isValidPassword(form.password)) {
- allErrors.password = 'The password has to consist of at least 8 characters.'
+ allErrors.password = t('auth.common.xCharsError', { amount: MIN_PASSWORD_CHARS })
}
if (form.password !== form.repeat || form.repeat === '') {
- allErrors.repeat = 'Passwords have to match.'
+ allErrors.repeat = t('auth.common.noMatchError')
}
if (!form.tos) {
- allErrors.tos = 'You have to accept our TOS and privacy policy in order to use our services.'
+ allErrors.tos = t('auth.common.tosError')
}
const valid = Object.keys(allErrors).length === 0
@@ -82,17 +86,17 @@ const Signup = ({ signup }) => {
}
return (
- <Title title='Sign up'>
+ <Title title={t('titles.signup')}>
<div className='min-h-page bg-gray-50 flex flex-col py-6 px-4 sm:px-6 lg:px-8'>
<form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
<h2 className='mt-2 text-3xl font-extrabold text-gray-900'>
- Sign up
+ {t('titles.signup')}
</h2>
<Input
name='email'
id='email'
type='email'
- label='Email'
+ label={t('auth.common.email')}
value={form.email}
placeholder='[email protected]'
className='mt-4'
@@ -103,10 +107,10 @@ const Signup = ({ signup }) => {
name='password'
id='password'
type='password'
- label='Password'
- hint='Longer than 8 chars'
+ label={t('auth.common.password')}
+ hint={t('auth.common.hint', { amount: MIN_PASSWORD_CHARS })}
value={form.password}
- placeholder='Password'
+ placeholder={t('auth.common.password')}
className='mt-4'
onChange={handleInput}
error={beenSubmitted ? errors.password : ''}
@@ -115,9 +119,9 @@ const Signup = ({ signup }) => {
name='repeat'
id='repeat'
type='password'
- label='Repeat password'
+ label={t('auth.common.repeat')}
value={form.repeat}
- placeholder='Repeat password'
+ placeholder={t('auth.common.repeat')}
className='mt-4'
onChange={handleInput}
error={beenSubmitted ? errors.repeat : ''}
@@ -130,15 +134,14 @@ const Signup = ({ signup }) => {
className='mt-4'
label={
<span>
- I do accept&nbsp;
- <Link to={routes.terms} className='font-medium text-gray-900 hover:underline'>
- Terms and Conditions
- </Link>
- &nbsp;and the&nbsp;
- <Link to={routes.privacy} className='font-medium text-gray-900 hover:underline'>
- Privacy Policy
- </Link>
- .
+ <Trans
+ t={t}
+ i18nKey='auth.signup.tos'
+ components={{
+ tos: <Link to={routes.terms} className='font-medium text-gray-900 hover:underline' />,
+ pp: <Link to={routes.privacy} className='font-medium text-gray-900 hover:underline' />,
+ }}
+ />
</span>
}
hint={beenSubmitted ? errors.tos : ''}
@@ -149,14 +152,14 @@ const Signup = ({ signup }) => {
name='keep_signedin'
id='keep_signedin'
className='mt-4'
- label={'Don\'t remember me.'}
+ label={t('auth.common.noRemember')}
/>
<div className='pt-1 flex justify-between mt-3'>
<Link to={routes.signin} className='underline text-blue-600 hover:text-indigo-800'>
- Sign in instead
+ {t('auth.common.signinInstead')}
</Link>
<Button type='submit' loading={isLoading} primary large>
- Sign up
+ {t('auth.signup.button')}
</Button>
</div>
</form>
diff --git a/src/pages/Auth/VerifyEmail/index.jsx b/src/pages/Auth/VerifyEmail/index.jsx
index bb588875b..a295022b0 100644
--- a/src/pages/Auth/VerifyEmail/index.jsx
+++ b/src/pages/Auth/VerifyEmail/index.jsx
@@ -1,6 +1,7 @@
import React, { useState, useEffect, memo } from 'react'
import { useDispatch } from 'react-redux'
import { useParams } from 'react-router-dom'
+import { useTranslation } from 'react-i18next'
import { CheckCircleIcon } from '@heroicons/react/solid'
import { XCircleIcon } from '@heroicons/react/solid'
@@ -9,6 +10,7 @@ import { authActions } from 'redux/actions/auth'
import Loader from 'ui/Loader'
const VerifyEmail = () => {
+ const { t } = useTranslation('common')
const dispatch = useDispatch()
const { id } = useParams()
const [loading, setLoading] = useState(true)
@@ -29,7 +31,7 @@ const VerifyEmail = () => {
if (loading) {
return (
- <Title title='Email verification'>
+ <Title title={t('titles.verification')}>
<Loader />
</Title>
)
@@ -37,7 +39,7 @@ const VerifyEmail = () => {
if (error) {
return (
- <Title title='Email verification'>
+ <Title title={t('titles.verification')}>
<div className='min-h-page'>
<div className='flex justify-center pt-10'>
<div className='rounded-md p-4 w-11/12 bg-red-50 lg:w-4/6'>
@@ -67,7 +69,7 @@ const VerifyEmail = () => {
</div>
<div className='ml-3'>
<h3 className='text-sm font-medium text-green-800'>
- Your email has been successfully verified!
+ {t('auth.verification.success')}
</h3>
</div>
</div>
diff --git a/src/utils/validator.js b/src/utils/validator.js
index f3bf59af1..064461768 100644
--- a/src/utils/validator.js
+++ b/src/utils/validator.js
@@ -1,7 +1,9 @@
import _includes from 'lodash/includes'
+export const MIN_PASSWORD_CHARS = 8
+
export const isValidEmail = text => text.match(/^\w+([.+-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,7})+$/)
-export const isValidPassword = text => text.length >= 8
+export const isValidPassword = text => text.length >= MIN_PASSWORD_CHARS
export const isAdmin = user => _includes(user.roles, 'admin')