API & Client - add API error messages translation
This commit is contained in:
parent
c5c84c4090
commit
f6389f1cdd
@ -370,7 +370,7 @@
|
||||
<li><p>Invalid token. Please log in again.</p></li>
|
||||
</ul>
|
||||
</p></li>
|
||||
<li><p><a class="reference external" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4">403 Forbidden</a> – You do not have permissions</p></li>
|
||||
<li><p><a class="reference external" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4">403 Forbidden</a> – You do not have permissions.</p></li>
|
||||
<li><p><a class="reference external" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5">404 Not Found</a> – activity not found</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
|
@ -177,10 +177,10 @@
|
||||
<li><p>Sorry. That user already exists.</p></li>
|
||||
<li><dl class="simple">
|
||||
<dt>Errors:</dt><dd><ul>
|
||||
<li><p>Username: 3 to 12 characters required.</p></li>
|
||||
<li><p>3 to 12 characters required for usernanme.</p></li>
|
||||
<li><p>Valid email must be provided.</p></li>
|
||||
<li><p>Password and password confirmation don’t match.</p></li>
|
||||
<li><p>Password: 8 characters required.</p></li>
|
||||
<li><p>8 characters required for password.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
|
@ -266,7 +266,7 @@
|
||||
</ul>
|
||||
</p></li>
|
||||
<li><p><a class="reference external" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5">404 Not Found</a> – <ul>
|
||||
<li><p>User does not exist</p></li>
|
||||
<li><p>User does not exist.</p></li>
|
||||
</ul>
|
||||
</p></li>
|
||||
</ul>
|
||||
@ -298,7 +298,7 @@
|
||||
<dd class="field-even"><ul class="simple">
|
||||
<li><p><a class="reference external" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.1">200 OK</a> – success</p></li>
|
||||
<li><p><a class="reference external" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5">404 Not Found</a> – <ul>
|
||||
<li><p>User does not exist</p></li>
|
||||
<li><p>User does not exist.</p></li>
|
||||
<li><p>No picture.</p></li>
|
||||
</ul>
|
||||
</p></li>
|
||||
|
File diff suppressed because one or more lines are too long
@ -341,7 +341,7 @@ def get_activity(auth_user_id, activity_id):
|
||||
- Provide a valid auth token.
|
||||
- Signature expired. Please log in again.
|
||||
- Invalid token. Please log in again.
|
||||
:statuscode 403: You do not have permissions
|
||||
:statuscode 403: You do not have permissions.
|
||||
:statuscode 404: activity not found
|
||||
|
||||
"""
|
||||
|
@ -63,8 +63,8 @@ def test_user_registration_invalid_short_username(app):
|
||||
data = json.loads(response.data.decode())
|
||||
assert data['status'] == 'error'
|
||||
assert (
|
||||
data['message'] == "Errors: Username: 3 to 12 characters required.\n"
|
||||
) # noqa
|
||||
data['message'] == "Username: 3 to 12 characters required.\n"
|
||||
)
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 400
|
||||
|
||||
@ -86,8 +86,8 @@ def test_user_registration_invalid_long_username(app):
|
||||
data = json.loads(response.data.decode())
|
||||
assert data['status'] == 'error'
|
||||
assert (
|
||||
data['message'] == "Errors: Username: 3 to 12 characters required.\n"
|
||||
) # noqa
|
||||
data['message'] == "Username: 3 to 12 characters required.\n"
|
||||
)
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 400
|
||||
|
||||
@ -108,7 +108,7 @@ def test_user_registration_invalid_email(app):
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
assert data['status'] == 'error'
|
||||
assert data['message'] == "Errors: Valid email must be provided.\n" # noqa
|
||||
assert data['message'] == "Valid email must be provided.\n"
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 400
|
||||
|
||||
@ -130,8 +130,8 @@ def test_user_registration_invalid_short_password(app):
|
||||
data = json.loads(response.data.decode())
|
||||
assert data['status'] == 'error'
|
||||
assert (
|
||||
data['message'] == "Errors: Password: 8 characters required.\n"
|
||||
) # noqa
|
||||
data['message'] == "Password: 8 characters required.\n"
|
||||
)
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 400
|
||||
|
||||
@ -154,8 +154,8 @@ def test_user_registration_mismatched_password(app):
|
||||
assert data['status'] == 'error'
|
||||
assert (
|
||||
data['message']
|
||||
== "Errors: Password and password confirmation don\'t match.\n"
|
||||
) # noqa
|
||||
== "Password and password confirmation don\'t match.\n"
|
||||
)
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 400
|
||||
|
||||
@ -262,7 +262,7 @@ def test_user_registration_invalid_data(app):
|
||||
assert (
|
||||
'Error. Please try again or contact the administrator.'
|
||||
in data['message']
|
||||
) # noqa
|
||||
)
|
||||
assert 'error' in data['status']
|
||||
|
||||
|
||||
@ -700,7 +700,7 @@ def test_user_profile_invalid_password(app, user_1):
|
||||
assert data['status'] == 'error'
|
||||
assert (
|
||||
data['message'] == 'Password and password confirmation don\'t match.\n'
|
||||
) # noqa
|
||||
)
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
@ -736,7 +736,7 @@ def test_user_profile_missing_password_conf(app, user_1):
|
||||
assert data['status'] == 'error'
|
||||
assert (
|
||||
data['message'] == 'Password and password confirmation don\'t match.\n'
|
||||
) # noqa
|
||||
)
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
|
@ -68,10 +68,10 @@ def register_user():
|
||||
- Invalid payload.
|
||||
- Sorry. That user already exists.
|
||||
- Errors:
|
||||
- Username: 3 to 12 characters required.
|
||||
- 3 to 12 characters required for usernanme.
|
||||
- Valid email must be provided.
|
||||
- Password and password confirmation don't match.
|
||||
- Password: 8 characters required.
|
||||
- 8 characters required for password.
|
||||
:statuscode 403:
|
||||
Error. Registration is disabled.
|
||||
:statuscode 500:
|
||||
@ -112,7 +112,7 @@ def register_user():
|
||||
}
|
||||
return jsonify(response_object), 500
|
||||
if ret != '':
|
||||
response_object = {'status': 'error', 'message': 'Errors: ' + ret}
|
||||
response_object = {'status': 'error', 'message': ret}
|
||||
return jsonify(response_object), 400
|
||||
|
||||
try:
|
||||
@ -553,7 +553,7 @@ def edit_picture(user_id):
|
||||
max_file_size = current_app.config['MAX_CONTENT_LENGTH']
|
||||
response_object = {
|
||||
'status': 'fail',
|
||||
'message': 'Error during picture update: file size exceeds '
|
||||
'message': 'Error during picture update, file size exceeds '
|
||||
f'{display_readable_file_size(max_file_size)}.',
|
||||
}
|
||||
return jsonify(response_object), 413
|
||||
|
@ -143,7 +143,7 @@ def get_single_user(auth_user_id, user_id):
|
||||
- Signature expired. Please log in again.
|
||||
- Invalid token. Please log in again.
|
||||
:statuscode 404:
|
||||
- User does not exist
|
||||
- User does not exist.
|
||||
"""
|
||||
|
||||
response_object = {'status': 'fail', 'message': 'User does not exist.'}
|
||||
@ -180,7 +180,7 @@ def get_picture(user_id):
|
||||
|
||||
:statuscode 200: success
|
||||
:statuscode 404:
|
||||
- User does not exist
|
||||
- User does not exist.
|
||||
- No picture.
|
||||
|
||||
"""
|
||||
|
@ -66,7 +66,7 @@ def verify_extension_and_size(file_type, req):
|
||||
elif file_extension != 'zip' and req.content_length > max_file_size:
|
||||
response_object = {
|
||||
'status': 'fail',
|
||||
'message': 'Error during picture update: file size exceeds '
|
||||
'message': 'Error during picture update, file size exceeds '
|
||||
f'{display_readable_file_size(max_file_size)}.',
|
||||
}
|
||||
code = 413
|
||||
|
@ -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,7 +78,8 @@ class UserForm extends React.Component {
|
||||
)
|
||||
}
|
||||
}
|
||||
export default connect(
|
||||
export default withTranslation()(
|
||||
connect(
|
||||
state => ({
|
||||
location: state.router.location,
|
||||
message: state.message,
|
||||
@ -83,3 +91,4 @@ export default connect(
|
||||
},
|
||||
})
|
||||
)(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."
|
||||
}
|
Loading…
Reference in New Issue
Block a user