API & Client - add API error messages translation

This commit is contained in:
Sam 2019-09-16 17:54:21 +02:00
parent c5c84c4090
commit f6389f1cdd
20 changed files with 118 additions and 50 deletions

View File

@ -370,7 +370,7 @@
<li><p>Invalid token. Please log in again.</p></li> <li><p>Invalid token. Please log in again.</p></li>
</ul> </ul>
</p></li> </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> <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> </ul>
</dd> </dd>

View File

@ -177,10 +177,10 @@
<li><p>Sorry. That user already exists.</p></li> <li><p>Sorry. That user already exists.</p></li>
<li><dl class="simple"> <li><dl class="simple">
<dt>Errors:</dt><dd><ul> <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>Valid email must be provided.</p></li>
<li><p>Password and password confirmation dont match.</p></li> <li><p>Password and password confirmation dont match.</p></li>
<li><p>Password: 8 characters required.</p></li> <li><p>8 characters required for password.</p></li>
</ul> </ul>
</dd> </dd>
</dl> </dl>

View File

@ -266,7 +266,7 @@
</ul> </ul>
</p></li> </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><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> </ul>
</p></li> </p></li>
</ul> </ul>
@ -298,7 +298,7 @@
<dd class="field-even"><ul class="simple"> <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.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><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> <li><p>No picture.</p></li>
</ul> </ul>
</p></li> </p></li>

File diff suppressed because one or more lines are too long

View File

@ -341,7 +341,7 @@ def get_activity(auth_user_id, activity_id):
- Provide a valid auth token. - Provide a valid auth token.
- Signature expired. Please log in again. - Signature expired. Please log in again.
- Invalid token. 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 :statuscode 404: activity not found
""" """

View File

@ -63,8 +63,8 @@ def test_user_registration_invalid_short_username(app):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert ( assert (
data['message'] == "Errors: Username: 3 to 12 characters required.\n" data['message'] == "Username: 3 to 12 characters required.\n"
) # noqa )
assert response.content_type == 'application/json' assert response.content_type == 'application/json'
assert response.status_code == 400 assert response.status_code == 400
@ -86,8 +86,8 @@ def test_user_registration_invalid_long_username(app):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert ( assert (
data['message'] == "Errors: Username: 3 to 12 characters required.\n" data['message'] == "Username: 3 to 12 characters required.\n"
) # noqa )
assert response.content_type == 'application/json' assert response.content_type == 'application/json'
assert response.status_code == 400 assert response.status_code == 400
@ -108,7 +108,7 @@ def test_user_registration_invalid_email(app):
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' 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.content_type == 'application/json'
assert response.status_code == 400 assert response.status_code == 400
@ -130,8 +130,8 @@ def test_user_registration_invalid_short_password(app):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert ( assert (
data['message'] == "Errors: Password: 8 characters required.\n" data['message'] == "Password: 8 characters required.\n"
) # noqa )
assert response.content_type == 'application/json' assert response.content_type == 'application/json'
assert response.status_code == 400 assert response.status_code == 400
@ -154,8 +154,8 @@ def test_user_registration_mismatched_password(app):
assert data['status'] == 'error' assert data['status'] == 'error'
assert ( assert (
data['message'] data['message']
== "Errors: Password and password confirmation don\'t match.\n" == "Password and password confirmation don\'t match.\n"
) # noqa )
assert response.content_type == 'application/json' assert response.content_type == 'application/json'
assert response.status_code == 400 assert response.status_code == 400
@ -262,7 +262,7 @@ def test_user_registration_invalid_data(app):
assert ( assert (
'Error. Please try again or contact the administrator.' 'Error. Please try again or contact the administrator.'
in data['message'] in data['message']
) # noqa )
assert 'error' in data['status'] assert 'error' in data['status']
@ -700,7 +700,7 @@ def test_user_profile_invalid_password(app, user_1):
assert data['status'] == 'error' assert data['status'] == 'error'
assert ( assert (
data['message'] == 'Password and password confirmation don\'t match.\n' data['message'] == 'Password and password confirmation don\'t match.\n'
) # noqa )
assert response.status_code == 400 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['status'] == 'error'
assert ( assert (
data['message'] == 'Password and password confirmation don\'t match.\n' data['message'] == 'Password and password confirmation don\'t match.\n'
) # noqa )
assert response.status_code == 400 assert response.status_code == 400

View File

@ -68,10 +68,10 @@ def register_user():
- Invalid payload. - Invalid payload.
- Sorry. That user already exists. - Sorry. That user already exists.
- Errors: - Errors:
- Username: 3 to 12 characters required. - 3 to 12 characters required for usernanme.
- Valid email must be provided. - Valid email must be provided.
- Password and password confirmation don't match. - Password and password confirmation don't match.
- Password: 8 characters required. - 8 characters required for password.
:statuscode 403: :statuscode 403:
Error. Registration is disabled. Error. Registration is disabled.
:statuscode 500: :statuscode 500:
@ -112,7 +112,7 @@ def register_user():
} }
return jsonify(response_object), 500 return jsonify(response_object), 500
if ret != '': if ret != '':
response_object = {'status': 'error', 'message': 'Errors: ' + ret} response_object = {'status': 'error', 'message': ret}
return jsonify(response_object), 400 return jsonify(response_object), 400
try: try:
@ -553,7 +553,7 @@ def edit_picture(user_id):
max_file_size = current_app.config['MAX_CONTENT_LENGTH'] max_file_size = current_app.config['MAX_CONTENT_LENGTH']
response_object = { response_object = {
'status': 'fail', '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)}.', f'{display_readable_file_size(max_file_size)}.',
} }
return jsonify(response_object), 413 return jsonify(response_object), 413

View File

@ -143,7 +143,7 @@ def get_single_user(auth_user_id, user_id):
- Signature expired. Please log in again. - Signature expired. Please log in again.
- Invalid token. Please log in again. - Invalid token. Please log in again.
:statuscode 404: :statuscode 404:
- User does not exist - User does not exist.
""" """
response_object = {'status': 'fail', 'message': '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 200: success
:statuscode 404: :statuscode 404:
- User does not exist - User does not exist.
- No picture. - No picture.
""" """

View File

@ -66,7 +66,7 @@ def verify_extension_and_size(file_type, req):
elif file_extension != 'zip' and req.content_length > max_file_size: elif file_extension != 'zip' and req.content_length > max_file_size:
response_object = { response_object = {
'status': 'fail', '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)}.', f'{display_readable_file_size(max_file_size)}.',
} }
code = 413 code = 413

View File

@ -61,13 +61,13 @@ export const loginOrRegister = (target, formData) => dispatch =>
const RegisterFormControl = formData => { const RegisterFormControl = formData => {
const errMsg = [] const errMsg = []
if (formData.username.length < 3 || formData.username.length > 12) { 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) { if (formData.password !== formData.password_conf) {
errMsg.push("Password and password confirmation don't match.") errMsg.push("Password and password confirmation don't match.")
} }
if (formData.password.length < 8) { if (formData.password.length < 8) {
errMsg.push('Password: 8 characters required.') errMsg.push('8 characters required for password.')
} }
return errMsg return errMsg
} }
@ -112,7 +112,10 @@ export const uploadPicture = event => dispatch => {
if (ret.status === 'success') { if (ret.status === 'success') {
return dispatch(getProfile()) 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 => { .catch(error => {
throw error throw error

View File

@ -55,7 +55,7 @@ class Activities extends React.Component {
<title>FitTrackee - {t('common:Workouts')}</title> <title>FitTrackee - {t('common:Workouts')}</title>
</Helmet> </Helmet>
{message ? ( {message ? (
<code>{message}</code> <code>{t(`messages:${message}`)}</code>
) : ( ) : (
<div className="container history"> <div className="container history">
<div className="row"> <div className="row">

View File

@ -38,7 +38,7 @@ class ActivityAddEdit extends React.Component {
</Helmet> </Helmet>
<br /> <br />
<br /> <br />
{message && <code>{message}</code>} {message && <code>{t(`messages:${message}`)}</code>}
<div className="container"> <div className="container">
<div className="row"> <div className="row">
<div className="col-md-2" /> <div className="col-md-2" />

View File

@ -85,7 +85,7 @@ class ActivityDisplay extends React.Component {
<title>FitTrackee - {title}</title> <title>FitTrackee - {title}</title>
</Helmet> </Helmet>
{message ? ( {message ? (
<code>{message}</code> <code>{t(`messages:${message}`)}</code>
) : ( ) : (
<div className="container"> <div className="container">
{displayModal && ( {displayModal && (

View File

@ -45,7 +45,7 @@ class DashBoard extends React.Component {
<title>FitTrackee - {t('common:Dashboard')}</title> <title>FitTrackee - {t('common:Dashboard')}</title>
</Helmet> </Helmet>
{message ? ( {message ? (
<code>{message}</code> <code>{t(`messages:${message}`)}</code>
) : ( ) : (
activities && activities &&
sports.length > 0 && ( sports.length > 0 && (

View File

@ -20,7 +20,7 @@ function Profile({ message, onDeletePicture, onUploadPicture, t, user }) {
<Helmet> <Helmet>
<title>FitTrackee - {t('user:Profile')}</title> <title>FitTrackee - {t('user:Profile')}</title>
</Helmet> </Helmet>
{message !== '' && <code>{message}</code>} {message !== '' && <code>{t(`messages:${message}`)}</code>}
<div className="container"> <div className="container">
<h1 className="page-title">{t('user:Profile')}</h1> <h1 className="page-title">{t('user:Profile')}</h1>
<div className="row"> <div className="row">

View File

@ -58,7 +58,7 @@ class ProfileEdit extends React.Component {
<Helmet> <Helmet>
<title>FitTrackee - {t('user:Profile Edition')}</title> <title>FitTrackee - {t('user:Profile Edition')}</title>
</Helmet> </Helmet>
{message !== '' && <code>{message}</code>} {message !== '' && <code>{t(`messages:${message}`)}</code>}
{formData.isAuthenticated && ( {formData.isAuthenticated && (
<div className="container"> <div className="container">
<h1 className="page-title">{t('user:Profile Edition')}</h1> <h1 className="page-title">{t('user:Profile Edition')}</h1>

View File

@ -5,6 +5,7 @@ import { Redirect } from 'react-router-dom'
import Form from './Form' import Form from './Form'
import { handleUserFormSubmit } from '../../actions/user' import { handleUserFormSubmit } from '../../actions/user'
import { isLoggedIn } from '../../utils' import { isLoggedIn } from '../../utils'
import { withTranslation } from 'react-i18next'
class UserForm extends React.Component { class UserForm extends React.Component {
constructor(props, context) { constructor(props, context) {
@ -38,7 +39,13 @@ class UserForm extends React.Component {
} }
render() { render() {
const { formType, message, messages, onHandleUserFormSubmit } = this.props const {
formType,
message,
messages,
onHandleUserFormSubmit,
t,
} = this.props
const { formData } = this.state const { formData } = this.state
return ( return (
<div> <div>
@ -46,12 +53,12 @@ class UserForm extends React.Component {
<Redirect to="/" /> <Redirect to="/" />
) : ( ) : (
<div> <div>
{message !== '' && <code>{message}</code>} {message !== '' && <code>{t(`messages:${message}`)}</code>}
{messages.length > 0 && ( {messages.length > 0 && (
<code> <code>
<ul> <ul>
{messages.map(msg => ( {messages.map(msg => (
<li key={msg.id}>{msg.value}</li> <li key={msg.id}>{t(`messages:${msg.value}`)}</li>
))} ))}
</ul> </ul>
</code> </code>
@ -71,7 +78,8 @@ class UserForm extends React.Component {
) )
} }
} }
export default connect( export default withTranslation()(
connect(
state => ({ state => ({
location: state.router.location, location: state.router.location,
message: state.message, message: state.message,
@ -83,3 +91,4 @@ export default connect(
}, },
}) })
)(UserForm) )(UserForm)
)

View File

@ -5,12 +5,14 @@ import XHR from 'i18next-xhr-backend'
import EnActivitiesTranslations from './locales/en/activities.json' import EnActivitiesTranslations from './locales/en/activities.json'
import EnCommonTranslations from './locales/en/common.json' import EnCommonTranslations from './locales/en/common.json'
import EnDashboardTranslations from './locales/en/dashboard.json' import EnDashboardTranslations from './locales/en/dashboard.json'
import EnMessagesTranslations from './locales/en/messages.json'
import EnSportsTranslations from './locales/en/sports.json' import EnSportsTranslations from './locales/en/sports.json'
import EnStatisticsTranslations from './locales/en/statistics.json' import EnStatisticsTranslations from './locales/en/statistics.json'
import EnUserTranslations from './locales/en/user.json' import EnUserTranslations from './locales/en/user.json'
import FrActivitiesTranslations from './locales/fr/activities.json' import FrActivitiesTranslations from './locales/fr/activities.json'
import FrCommonTranslations from './locales/fr/common.json' import FrCommonTranslations from './locales/fr/common.json'
import FrDashboardTranslations from './locales/fr/dashboard.json' import FrDashboardTranslations from './locales/fr/dashboard.json'
import FrMessagesTranslations from './locales/fr/messages.json'
import FrSportsTranslations from './locales/fr/sports.json' import FrSportsTranslations from './locales/fr/sports.json'
import FrStatisticsTranslations from './locales/fr/statistics.json' import FrStatisticsTranslations from './locales/fr/statistics.json'
import FrUserTranslations from './locales/fr/user.json' import FrUserTranslations from './locales/fr/user.json'
@ -31,6 +33,7 @@ i18n
activities: EnActivitiesTranslations, activities: EnActivitiesTranslations,
common: EnCommonTranslations, common: EnCommonTranslations,
dashboard: EnDashboardTranslations, dashboard: EnDashboardTranslations,
messages: EnMessagesTranslations,
sports: EnSportsTranslations, sports: EnSportsTranslations,
statistics: EnStatisticsTranslations, statistics: EnStatisticsTranslations,
user: EnUserTranslations, user: EnUserTranslations,
@ -39,6 +42,7 @@ i18n
activities: FrActivitiesTranslations, activities: FrActivitiesTranslations,
common: FrCommonTranslations, common: FrCommonTranslations,
dashboard: FrDashboardTranslations, dashboard: FrDashboardTranslations,
messages: FrMessagesTranslations,
sports: FrSportsTranslations, sports: FrSportsTranslations,
statistics: FrStatisticsTranslations, statistics: FrStatisticsTranslations,
user: FrUserTranslations, user: FrUserTranslations,

View 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."
}

View 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."
}