Skip to content

Commit a90ba2b

Browse files
committed
update error messages for language and consistency
1 parent faf76a4 commit a90ba2b

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

rest_framework/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class APIException(Exception):
3636
Subclasses should provide `.status_code` and `.default_detail` properties.
3737
"""
3838
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
39-
default_detail = _('A server error occurred')
39+
default_detail = _('A server error occurred.')
4040

4141
def __init__(self, detail=None):
4242
if detail is not None:
@@ -107,7 +107,7 @@ def __init__(self, method, detail=None):
107107

108108
class NotAcceptable(APIException):
109109
status_code = status.HTTP_406_NOT_ACCEPTABLE
110-
default_detail = _('Could not satisfy the request Accept header')
110+
default_detail = _('Could not satisfy the request Accept header.')
111111

112112
def __init__(self, detail=None, available_renderers=None):
113113
if detail is not None:

rest_framework/fields.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ class IntegerField(Field):
640640
'invalid': _('A valid integer is required.'),
641641
'max_value': _('Ensure this value is less than or equal to {max_value}.'),
642642
'min_value': _('Ensure this value is greater than or equal to {min_value}.'),
643-
'max_string_length': _('String value too large')
643+
'max_string_length': _('String value too large.')
644644
}
645645
MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs.
646646

@@ -674,7 +674,7 @@ class FloatField(Field):
674674
'invalid': _("A valid number is required."),
675675
'max_value': _('Ensure this value is less than or equal to {max_value}.'),
676676
'min_value': _('Ensure this value is greater than or equal to {min_value}.'),
677-
'max_string_length': _('String value too large')
677+
'max_string_length': _('String value too large.')
678678
}
679679
MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs.
680680

@@ -710,7 +710,7 @@ class DecimalField(Field):
710710
'max_digits': _('Ensure that there are no more than {max_digits} digits in total.'),
711711
'max_decimal_places': _('Ensure that there are no more than {max_decimal_places} decimal places.'),
712712
'max_whole_digits': _('Ensure that there are no more than {max_whole_digits} digits before the decimal point.'),
713-
'max_string_length': _('String value too large')
713+
'max_string_length': _('String value too large.')
714714
}
715715
MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs.
716716

@@ -793,7 +793,7 @@ def to_representation(self, value):
793793

794794
class DateTimeField(Field):
795795
default_error_messages = {
796-
'invalid': _('Datetime has wrong format. Use one of these formats instead: {format}'),
796+
'invalid': _('Datetime has wrong format. Use one of these formats instead: {format}.'),
797797
'date': _('Expected a datetime but got a date.'),
798798
}
799799
format = api_settings.DATETIME_FORMAT
@@ -858,7 +858,7 @@ def to_representation(self, value):
858858

859859
class DateField(Field):
860860
default_error_messages = {
861-
'invalid': _('Date has wrong format. Use one of these formats instead: {format}'),
861+
'invalid': _('Date has wrong format. Use one of these formats instead: {format}.'),
862862
'datetime': _('Expected a date but got a datetime.'),
863863
}
864864
format = api_settings.DATE_FORMAT
@@ -916,7 +916,7 @@ def to_representation(self, value):
916916

917917
class TimeField(Field):
918918
default_error_messages = {
919-
'invalid': _('Time has wrong format. Use one of these formats instead: {format}'),
919+
'invalid': _('Time has wrong format. Use one of these formats instead: {format}.'),
920920
}
921921
format = api_settings.TIME_FORMAT
922922
input_formats = api_settings.TIME_INPUT_FORMATS
@@ -1093,8 +1093,7 @@ def to_representation(self, value):
10931093
class ImageField(FileField):
10941094
default_error_messages = {
10951095
'invalid_image': _(
1096-
'Upload a valid image. The file you uploaded was either not an '
1097-
'image or a corrupted image.'
1096+
'Upload a valid image. The file you uploaded was either not an image or a corrupted image.'
10981097
),
10991098
}
11001099

@@ -1119,7 +1118,7 @@ class ListField(Field):
11191118
child = None
11201119
initial = []
11211120
default_error_messages = {
1122-
'not_a_list': _('Expected a list of items but got type `{input_type}`')
1121+
'not_a_list': _('Expected a list of items but got type `{input_type}`.')
11231122
}
11241123

11251124
def __init__(self, *args, **kwargs):

rest_framework/generics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def paginate_queryset(self, queryset):
119119
if page == 'last':
120120
page_number = paginator.num_pages
121121
else:
122-
raise Http404(_("Page is not 'last', and cannot be converted to an int."))
122+
raise Http404(_("Choose a valid page number. Page numbers must be a whole number, or must be the string 'last'."))
123123
try:
124124
page = paginator.page(page_number)
125125
except InvalidPage as exc:

rest_framework/locale/en_US/LC_MESSAGES/django.po

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
33
# This file is distributed under the same license as the PACKAGE package.
44
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5-
#
5+
#
66
#, fuzzy
77
msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2014-12-31 12:48+0000\n"
11+
"POT-Creation-Date: 2014-12-31 13:02+0000\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -30,7 +30,7 @@ msgid "Must include \"username\" and \"password\""
3030
msgstr ""
3131

3232
#: rest_framework/exceptions.py:39
33-
msgid "A server error occurred"
33+
msgid "A server error occurred."
3434
msgstr ""
3535

3636
#: rest_framework/exceptions.py:74
@@ -55,7 +55,7 @@ msgid "Method '%s' not allowed."
5555
msgstr ""
5656

5757
#: rest_framework/exceptions.py:105
58-
msgid "Could not satisfy the request Accept header"
58+
msgid "Could not satisfy the request Accept header."
5959
msgstr ""
6060

6161
#: rest_framework/exceptions.py:117
@@ -92,7 +92,7 @@ msgstr ""
9292
msgid "This field may not be blank."
9393
msgstr ""
9494

95-
#: rest_framework/fields.py:548 rest_framework/fields.py:1250
95+
#: rest_framework/fields.py:548 rest_framework/fields.py:1249
9696
msgid "Ensure this field has no more than {max_length} characters."
9797
msgstr ""
9898

@@ -133,7 +133,7 @@ msgstr ""
133133

134134
#: rest_framework/fields.py:640 rest_framework/fields.py:674
135135
#: rest_framework/fields.py:710
136-
msgid "String value too large"
136+
msgid "String value too large."
137137
msgstr ""
138138

139139
#: rest_framework/fields.py:671 rest_framework/fields.py:704
@@ -155,30 +155,31 @@ msgid ""
155155
msgstr ""
156156

157157
#: rest_framework/fields.py:793
158-
msgid "Datetime has wrong format. Use one of these formats instead: {format}"
158+
msgid "Datetime has wrong format. Use one of these formats instead: {format}."
159159
msgstr ""
160160

161161
#: rest_framework/fields.py:794
162162
msgid "Expected a datetime but got a date."
163163
msgstr ""
164164

165165
#: rest_framework/fields.py:858
166-
msgid "Date has wrong format. Use one of these formats instead: {format}"
166+
msgid "Date has wrong format. Use one of these formats instead: {format}."
167167
msgstr ""
168168

169169
#: rest_framework/fields.py:859
170170
msgid "Expected a date but got a datetime."
171171
msgstr ""
172172

173173
#: rest_framework/fields.py:916
174-
msgid "Time has wrong format. Use one of these formats instead: {format}"
174+
msgid "Time has wrong format. Use one of these formats instead: {format}."
175175
msgstr ""
176176

177177
#: rest_framework/fields.py:972 rest_framework/fields.py:1016
178178
msgid "`{input}` is not a valid choice."
179179
msgstr ""
180180

181-
#: rest_framework/fields.py:1017 rest_framework/serializers.py:474
181+
#: rest_framework/fields.py:1017 rest_framework/fields.py:1118
182+
#: rest_framework/serializers.py:474
182183
msgid "Expected a list of items but got type `{input_type}`."
183184
msgstr ""
184185

@@ -204,15 +205,15 @@ msgid ""
204205
msgstr ""
205206

206207
#: rest_framework/fields.py:1093
207-
msgid "Upload a valid image. The file you uploaded was either not an "
208-
msgstr ""
209-
210-
#: rest_framework/fields.py:1119
211-
msgid "Expected a list of items but got type `{input_type}`"
208+
msgid ""
209+
"Upload a valid image. The file you uploaded was either not an image or a "
210+
"corrupted image."
212211
msgstr ""
213212

214213
#: rest_framework/generics.py:122
215-
msgid "Page is not 'last', and cannot be converted to an int."
214+
msgid ""
215+
"Choose a valid page number. Page numbers must be a whole number, or must be "
216+
"the string 'last'."
216217
msgstr ""
217218

218219
#: rest_framework/generics.py:126

0 commit comments

Comments
 (0)