API & Client - add API error messages translation
This commit is contained in:
@ -61,13 +61,13 @@ export const loginOrRegister = (target, formData) => dispatch =>
|
||||
const RegisterFormControl = formData => {
|
||||
const errMsg = []
|
||||
if (formData.username.length < 3 || formData.username.length > 12) {
|
||||
errMsg.push('Username: 3 to 12 characters required.')
|
||||
errMsg.push('3 to 12 characters required for username.')
|
||||
}
|
||||
if (formData.password !== formData.password_conf) {
|
||||
errMsg.push("Password and password confirmation don't match.")
|
||||
}
|
||||
if (formData.password.length < 8) {
|
||||
errMsg.push('Password: 8 characters required.')
|
||||
errMsg.push('8 characters required for password.')
|
||||
}
|
||||
return errMsg
|
||||
}
|
||||
@ -112,7 +112,10 @@ export const uploadPicture = event => dispatch => {
|
||||
if (ret.status === 'success') {
|
||||
return dispatch(getProfile())
|
||||
}
|
||||
return dispatch(PictureError(ret.message))
|
||||
const msg = ret.message.match(/file size exceeds/g)
|
||||
? 'Error during picture update, file size exceeds max size.'
|
||||
: ret.message
|
||||
return dispatch(PictureError(msg))
|
||||
})
|
||||
.catch(error => {
|
||||
throw error
|
||||
|
@ -55,7 +55,7 @@ class Activities extends React.Component {
|
||||
<title>FitTrackee - {t('common:Workouts')}</title>
|
||||
</Helmet>
|
||||
{message ? (
|
||||
<code>{message}</code>
|
||||
<code>{t(`messages:${message}`)}</code>
|
||||
) : (
|
||||
<div className="container history">
|
||||
<div className="row">
|
||||
|
@ -38,7 +38,7 @@ class ActivityAddEdit extends React.Component {
|
||||
</Helmet>
|
||||
<br />
|
||||
<br />
|
||||
{message && <code>{message}</code>}
|
||||
{message && <code>{t(`messages:${message}`)}</code>}
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
<div className="col-md-2" />
|
||||
|
@ -85,7 +85,7 @@ class ActivityDisplay extends React.Component {
|
||||
<title>FitTrackee - {title}</title>
|
||||
</Helmet>
|
||||
{message ? (
|
||||
<code>{message}</code>
|
||||
<code>{t(`messages:${message}`)}</code>
|
||||
) : (
|
||||
<div className="container">
|
||||
{displayModal && (
|
||||
|
@ -45,7 +45,7 @@ class DashBoard extends React.Component {
|
||||
<title>FitTrackee - {t('common:Dashboard')}</title>
|
||||
</Helmet>
|
||||
{message ? (
|
||||
<code>{message}</code>
|
||||
<code>{t(`messages:${message}`)}</code>
|
||||
) : (
|
||||
activities &&
|
||||
sports.length > 0 && (
|
||||
|
@ -20,7 +20,7 @@ function Profile({ message, onDeletePicture, onUploadPicture, t, user }) {
|
||||
<Helmet>
|
||||
<title>FitTrackee - {t('user:Profile')}</title>
|
||||
</Helmet>
|
||||
{message !== '' && <code>{message}</code>}
|
||||
{message !== '' && <code>{t(`messages:${message}`)}</code>}
|
||||
<div className="container">
|
||||
<h1 className="page-title">{t('user:Profile')}</h1>
|
||||
<div className="row">
|
||||
|
@ -58,7 +58,7 @@ class ProfileEdit extends React.Component {
|
||||
<Helmet>
|
||||
<title>FitTrackee - {t('user:Profile Edition')}</title>
|
||||
</Helmet>
|
||||
{message !== '' && <code>{message}</code>}
|
||||
{message !== '' && <code>{t(`messages:${message}`)}</code>}
|
||||
{formData.isAuthenticated && (
|
||||
<div className="container">
|
||||
<h1 className="page-title">{t('user:Profile Edition')}</h1>
|
||||
|
@ -5,6 +5,7 @@ import { Redirect } from 'react-router-dom'
|
||||
import Form from './Form'
|
||||
import { handleUserFormSubmit } from '../../actions/user'
|
||||
import { isLoggedIn } from '../../utils'
|
||||
import { withTranslation } from 'react-i18next'
|
||||
|
||||
class UserForm extends React.Component {
|
||||
constructor(props, context) {
|
||||
@ -38,7 +39,13 @@ class UserForm extends React.Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { formType, message, messages, onHandleUserFormSubmit } = this.props
|
||||
const {
|
||||
formType,
|
||||
message,
|
||||
messages,
|
||||
onHandleUserFormSubmit,
|
||||
t,
|
||||
} = this.props
|
||||
const { formData } = this.state
|
||||
return (
|
||||
<div>
|
||||
@ -46,12 +53,12 @@ class UserForm extends React.Component {
|
||||
<Redirect to="/" />
|
||||
) : (
|
||||
<div>
|
||||
{message !== '' && <code>{message}</code>}
|
||||
{message !== '' && <code>{t(`messages:${message}`)}</code>}
|
||||
{messages.length > 0 && (
|
||||
<code>
|
||||
<ul>
|
||||
{messages.map(msg => (
|
||||
<li key={msg.id}>{msg.value}</li>
|
||||
<li key={msg.id}>{t(`messages:${msg.value}`)}</li>
|
||||
))}
|
||||
</ul>
|
||||
</code>
|
||||
@ -71,15 +78,17 @@ class UserForm extends React.Component {
|
||||
)
|
||||
}
|
||||
}
|
||||
export default connect(
|
||||
state => ({
|
||||
location: state.router.location,
|
||||
message: state.message,
|
||||
messages: state.messages,
|
||||
}),
|
||||
dispatch => ({
|
||||
onHandleUserFormSubmit: (formData, formType) => {
|
||||
dispatch(handleUserFormSubmit(formData, formType))
|
||||
},
|
||||
})
|
||||
)(UserForm)
|
||||
export default withTranslation()(
|
||||
connect(
|
||||
state => ({
|
||||
location: state.router.location,
|
||||
message: state.message,
|
||||
messages: state.messages,
|
||||
}),
|
||||
dispatch => ({
|
||||
onHandleUserFormSubmit: (formData, formType) => {
|
||||
dispatch(handleUserFormSubmit(formData, formType))
|
||||
},
|
||||
})
|
||||
)(UserForm)
|
||||
)
|
||||
|
@ -5,12 +5,14 @@ import XHR from 'i18next-xhr-backend'
|
||||
import EnActivitiesTranslations from './locales/en/activities.json'
|
||||
import EnCommonTranslations from './locales/en/common.json'
|
||||
import EnDashboardTranslations from './locales/en/dashboard.json'
|
||||
import EnMessagesTranslations from './locales/en/messages.json'
|
||||
import EnSportsTranslations from './locales/en/sports.json'
|
||||
import EnStatisticsTranslations from './locales/en/statistics.json'
|
||||
import EnUserTranslations from './locales/en/user.json'
|
||||
import FrActivitiesTranslations from './locales/fr/activities.json'
|
||||
import FrCommonTranslations from './locales/fr/common.json'
|
||||
import FrDashboardTranslations from './locales/fr/dashboard.json'
|
||||
import FrMessagesTranslations from './locales/fr/messages.json'
|
||||
import FrSportsTranslations from './locales/fr/sports.json'
|
||||
import FrStatisticsTranslations from './locales/fr/statistics.json'
|
||||
import FrUserTranslations from './locales/fr/user.json'
|
||||
@ -31,6 +33,7 @@ i18n
|
||||
activities: EnActivitiesTranslations,
|
||||
common: EnCommonTranslations,
|
||||
dashboard: EnDashboardTranslations,
|
||||
messages: EnMessagesTranslations,
|
||||
sports: EnSportsTranslations,
|
||||
statistics: EnStatisticsTranslations,
|
||||
user: EnUserTranslations,
|
||||
@ -39,6 +42,7 @@ i18n
|
||||
activities: FrActivitiesTranslations,
|
||||
common: FrCommonTranslations,
|
||||
dashboard: FrDashboardTranslations,
|
||||
messages: FrMessagesTranslations,
|
||||
sports: FrSportsTranslations,
|
||||
statistics: FrStatisticsTranslations,
|
||||
user: FrUserTranslations,
|
||||
|
26
fittrackee_client/src/locales/en/messages.json
Normal file
26
fittrackee_client/src/locales/en/messages.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"3 to 12 characters required for username.": "3 to 12 characters required for username.",
|
||||
"8 characters required for password.": "8 characters required for password.",
|
||||
"An error occurred. Please contact the administrator.": "An error occurred. Please contact the administrator.",
|
||||
"Error during picture deletion.": "Error during picture deletion.",
|
||||
"Error during picture update.": "Error during picture update.",
|
||||
"Error during picture update, file size exceeds max size.": "Error during picture update, file size exceeds max size.",
|
||||
"Error. Registration is disabled.": "Error. Registration is disabled.",
|
||||
"Error. Please try again or contact the administrator.": "Error. Please try again or contact the administrator.",
|
||||
"File extension not allowed.": "File extension not allowed.",
|
||||
"Invalid credentials.": "Invalid credentials.",
|
||||
"Invalid payload.": "Invalid payload.",
|
||||
"Invalid token. Please log in again.": "Invalid token. Please log in again.",
|
||||
"No file part.": "No file part.",
|
||||
"No picture.": "No picture.",
|
||||
"No selected file.": "No selected file.",
|
||||
"no gpx file for this activity": "no gpx file for this activity",
|
||||
"Password and password confirmation don't match.": "Password and password confirmation don't match.",
|
||||
"Provide a valid auth token": "Provide a valid auth token",
|
||||
"Signature expired. Please log in again.": "Signature expired. Please log in again.",
|
||||
"Sorry. That user already exists.": "Sorry. That user already exists.",
|
||||
"Sport does not exist.": "Sport does not exist.",
|
||||
"User does not exist.": "User does not exist.",
|
||||
"Valid email must be provided.\n": "Valid email must be provided.",
|
||||
"You do not have permissions.": "You do not have permissions."
|
||||
}
|
26
fittrackee_client/src/locales/fr/messages.json
Normal file
26
fittrackee_client/src/locales/fr/messages.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"3 to 12 characters required for username.": "3 à 12 caractères requis pour le nom.",
|
||||
"8 characters required for password.": "8 caractères minimum pour le mot de passe.",
|
||||
"An error occurred. Please contact the administrator.": "Une erreur s'est produite. Merci de contacter l'administrateur.",
|
||||
"Error during picture deletion.": "Erreur lors de la suppression de l'image.",
|
||||
"Error during picture update.": "Erreur lors de la mise à jour de l'image.",
|
||||
"Error during picture update, file size exceeds max size.": "Erreur lors de la mise à jour de l'image, la taille du ficher dépasse la taille maximum autorisée",
|
||||
"Error. Registration is disabled.": "Erreur. L'inscription est désactivée.",
|
||||
"Error. Please try again or contact the administrator.": "Erreur. Veuillez réessayer ou contacter l'administrateur",
|
||||
"File extension not allowed.": "Extension de fichier non autorisée",
|
||||
"Invalid credentials.": "Identifiants invalides.",
|
||||
"Invalid payload.": "Données incorrectes.",
|
||||
"Invalid token. Please log in again.": "Jeton invalide. Merci de vous reconnecter.",
|
||||
"No file part.": "Pas de fichier fourni.",
|
||||
"No picture.": "Pas d'image.",
|
||||
"No selected file.": "Pas de fichier sélectionné.",
|
||||
"no gpx file for this activity": "pas de fichier gpx pour cette activité",
|
||||
"Password and password confirmation don't match.": "Les mots de passe saisis sont différents.",
|
||||
"Provide a valid auth token": "Merci de fournir un jeton valide",
|
||||
"Signature expired. Please log in again.": "Signature expirée. Merci de vous reconnecter.",
|
||||
"Sorry. That user already exists.": "Désolé. Cet utilisateur existe déjà.",
|
||||
"Sport does not exist.": "Le sport n'existe pas.",
|
||||
"User does not exist.": "L'utilisateur n'existe pas.",
|
||||
"Valid email must be provided.\n": "L'email fourni n'est pas valide.",
|
||||
"You do not have permissions.": "Vous n'avez pas les permissions nécessaires."
|
||||
}
|
Reference in New Issue
Block a user