From a90ba2bc11de5fb391b95d4fce84f87ae7f88eff Mon Sep 17 00:00:00 2001 From: Craig Blaszczyk Date: Wed, 31 Dec 2014 13:03:16 +0000 Subject: [PATCH] update error messages for language and consistency --- rest_framework/exceptions.py | 4 +-- rest_framework/fields.py | 17 +++++----- rest_framework/generics.py | 2 +- .../locale/en_US/LC_MESSAGES/django.po | 33 ++++++++++--------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/rest_framework/exceptions.py b/rest_framework/exceptions.py index 2586fc332..d78b7e975 100644 --- a/rest_framework/exceptions.py +++ b/rest_framework/exceptions.py @@ -36,7 +36,7 @@ class APIException(Exception): Subclasses should provide `.status_code` and `.default_detail` properties. """ status_code = status.HTTP_500_INTERNAL_SERVER_ERROR - default_detail = _('A server error occurred') + default_detail = _('A server error occurred.') def __init__(self, detail=None): if detail is not None: @@ -107,7 +107,7 @@ class MethodNotAllowed(APIException): class NotAcceptable(APIException): status_code = status.HTTP_406_NOT_ACCEPTABLE - default_detail = _('Could not satisfy the request Accept header') + default_detail = _('Could not satisfy the request Accept header.') def __init__(self, detail=None, available_renderers=None): if detail is not None: diff --git a/rest_framework/fields.py b/rest_framework/fields.py index c40dc3fb3..0ff2b0733 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -640,7 +640,7 @@ class IntegerField(Field): 'invalid': _('A valid integer is required.'), 'max_value': _('Ensure this value is less than or equal to {max_value}.'), 'min_value': _('Ensure this value is greater than or equal to {min_value}.'), - 'max_string_length': _('String value too large') + 'max_string_length': _('String value too large.') } MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs. @@ -674,7 +674,7 @@ class FloatField(Field): 'invalid': _("A valid number is required."), 'max_value': _('Ensure this value is less than or equal to {max_value}.'), 'min_value': _('Ensure this value is greater than or equal to {min_value}.'), - 'max_string_length': _('String value too large') + 'max_string_length': _('String value too large.') } MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs. @@ -710,7 +710,7 @@ class DecimalField(Field): 'max_digits': _('Ensure that there are no more than {max_digits} digits in total.'), 'max_decimal_places': _('Ensure that there are no more than {max_decimal_places} decimal places.'), 'max_whole_digits': _('Ensure that there are no more than {max_whole_digits} digits before the decimal point.'), - 'max_string_length': _('String value too large') + 'max_string_length': _('String value too large.') } MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs. @@ -793,7 +793,7 @@ class DecimalField(Field): class DateTimeField(Field): default_error_messages = { - 'invalid': _('Datetime has wrong format. Use one of these formats instead: {format}'), + 'invalid': _('Datetime has wrong format. Use one of these formats instead: {format}.'), 'date': _('Expected a datetime but got a date.'), } format = api_settings.DATETIME_FORMAT @@ -858,7 +858,7 @@ class DateTimeField(Field): class DateField(Field): default_error_messages = { - 'invalid': _('Date has wrong format. Use one of these formats instead: {format}'), + 'invalid': _('Date has wrong format. Use one of these formats instead: {format}.'), 'datetime': _('Expected a date but got a datetime.'), } format = api_settings.DATE_FORMAT @@ -916,7 +916,7 @@ class DateField(Field): class TimeField(Field): default_error_messages = { - 'invalid': _('Time has wrong format. Use one of these formats instead: {format}'), + 'invalid': _('Time has wrong format. Use one of these formats instead: {format}.'), } format = api_settings.TIME_FORMAT input_formats = api_settings.TIME_INPUT_FORMATS @@ -1093,8 +1093,7 @@ class FileField(Field): class ImageField(FileField): default_error_messages = { 'invalid_image': _( - 'Upload a valid image. The file you uploaded was either not an ' - 'image or a corrupted image.' + 'Upload a valid image. The file you uploaded was either not an image or a corrupted image.' ), } @@ -1119,7 +1118,7 @@ class ListField(Field): child = None initial = [] default_error_messages = { - 'not_a_list': _('Expected a list of items but got type `{input_type}`') + 'not_a_list': _('Expected a list of items but got type `{input_type}`.') } def __init__(self, *args, **kwargs): diff --git a/rest_framework/generics.py b/rest_framework/generics.py index bdbc19a75..680992d75 100644 --- a/rest_framework/generics.py +++ b/rest_framework/generics.py @@ -119,7 +119,7 @@ class GenericAPIView(views.APIView): if page == 'last': page_number = paginator.num_pages else: - raise Http404(_("Page is not 'last', and cannot be converted to an int.")) + raise Http404(_("Choose a valid page number. Page numbers must be a whole number, or must be the string 'last'.")) try: page = paginator.page(page_number) except InvalidPage as exc: diff --git a/rest_framework/locale/en_US/LC_MESSAGES/django.po b/rest_framework/locale/en_US/LC_MESSAGES/django.po index 3bed91430..18f5fe18d 100644 --- a/rest_framework/locale/en_US/LC_MESSAGES/django.po +++ b/rest_framework/locale/en_US/LC_MESSAGES/django.po @@ -2,13 +2,13 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. -# +# #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-12-31 12:48+0000\n" +"POT-Creation-Date: 2014-12-31 13:02+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -30,7 +30,7 @@ msgid "Must include \"username\" and \"password\"" msgstr "" #: rest_framework/exceptions.py:39 -msgid "A server error occurred" +msgid "A server error occurred." msgstr "" #: rest_framework/exceptions.py:74 @@ -55,7 +55,7 @@ msgid "Method '%s' not allowed." msgstr "" #: rest_framework/exceptions.py:105 -msgid "Could not satisfy the request Accept header" +msgid "Could not satisfy the request Accept header." msgstr "" #: rest_framework/exceptions.py:117 @@ -92,7 +92,7 @@ msgstr "" msgid "This field may not be blank." msgstr "" -#: rest_framework/fields.py:548 rest_framework/fields.py:1250 +#: rest_framework/fields.py:548 rest_framework/fields.py:1249 msgid "Ensure this field has no more than {max_length} characters." msgstr "" @@ -133,7 +133,7 @@ msgstr "" #: rest_framework/fields.py:640 rest_framework/fields.py:674 #: rest_framework/fields.py:710 -msgid "String value too large" +msgid "String value too large." msgstr "" #: rest_framework/fields.py:671 rest_framework/fields.py:704 @@ -155,7 +155,7 @@ msgid "" msgstr "" #: rest_framework/fields.py:793 -msgid "Datetime has wrong format. Use one of these formats instead: {format}" +msgid "Datetime has wrong format. Use one of these formats instead: {format}." msgstr "" #: rest_framework/fields.py:794 @@ -163,7 +163,7 @@ msgid "Expected a datetime but got a date." msgstr "" #: rest_framework/fields.py:858 -msgid "Date has wrong format. Use one of these formats instead: {format}" +msgid "Date has wrong format. Use one of these formats instead: {format}." msgstr "" #: rest_framework/fields.py:859 @@ -171,14 +171,15 @@ msgid "Expected a date but got a datetime." msgstr "" #: rest_framework/fields.py:916 -msgid "Time has wrong format. Use one of these formats instead: {format}" +msgid "Time has wrong format. Use one of these formats instead: {format}." msgstr "" #: rest_framework/fields.py:972 rest_framework/fields.py:1016 msgid "`{input}` is not a valid choice." msgstr "" -#: rest_framework/fields.py:1017 rest_framework/serializers.py:474 +#: rest_framework/fields.py:1017 rest_framework/fields.py:1118 +#: rest_framework/serializers.py:474 msgid "Expected a list of items but got type `{input_type}`." msgstr "" @@ -204,15 +205,15 @@ msgid "" msgstr "" #: rest_framework/fields.py:1093 -msgid "Upload a valid image. The file you uploaded was either not an " -msgstr "" - -#: rest_framework/fields.py:1119 -msgid "Expected a list of items but got type `{input_type}`" +msgid "" +"Upload a valid image. The file you uploaded was either not an image or a " +"corrupted image." msgstr "" #: rest_framework/generics.py:122 -msgid "Page is not 'last', and cannot be converted to an int." +msgid "" +"Choose a valid page number. Page numbers must be a whole number, or must be " +"the string 'last'." msgstr "" #: rest_framework/generics.py:126