|
10 | 10 | """ |
11 | 11 |
|
12 | 12 | import re |
| 13 | +import os |
13 | 14 |
|
14 | 15 | from docutils import nodes |
15 | 16 |
|
|
26 | 27 | from sphinx.util.nodes import make_refnode |
27 | 28 | from sphinx.util.docfields import GroupedField, TypedField |
28 | 29 | from sphinx.util.docutils import Reporter, LoggingReporter |
29 | | -from sphinx.locale import _ |
| 30 | +from sphinx.locale import get_translation |
| 31 | +_ = get_translation('httpdomain') |
30 | 32 |
|
31 | 33 | logger = logging.getLogger(__name__) |
32 | 34 |
|
@@ -186,59 +188,59 @@ def __init__(self, name, type): |
186 | 188 |
|
187 | 189 |
|
188 | 190 | HTTP_STATUS_CODES = { |
189 | | - 100: 'Continue', |
190 | | - 101: 'Switching Protocols', |
191 | | - 102: 'Processing', |
192 | | - 200: 'OK', |
193 | | - 201: 'Created', |
194 | | - 202: 'Accepted', |
195 | | - 203: 'Non Authoritative Information', |
196 | | - 204: 'No Content', |
197 | | - 205: 'Reset Content', |
198 | | - 206: 'Partial Content', |
199 | | - 207: 'Multi Status', |
200 | | - 226: 'IM Used', # see RFC 3229 |
201 | | - 300: 'Multiple Choices', |
202 | | - 301: 'Moved Permanently', |
203 | | - 302: 'Found', |
204 | | - 303: 'See Other', |
205 | | - 304: 'Not Modified', |
206 | | - 305: 'Use Proxy', |
207 | | - 307: 'Temporary Redirect', |
208 | | - 400: 'Bad Request', |
209 | | - 401: 'Unauthorized', |
210 | | - 402: 'Payment Required', # unused |
211 | | - 403: 'Forbidden', |
212 | | - 404: 'Not Found', |
213 | | - 405: 'Method Not Allowed', |
214 | | - 406: 'Not Acceptable', |
215 | | - 407: 'Proxy Authentication Required', |
216 | | - 408: 'Request Timeout', |
217 | | - 409: 'Conflict', |
218 | | - 410: 'Gone', |
219 | | - 411: 'Length Required', |
220 | | - 412: 'Precondition Failed', |
221 | | - 413: 'Request Entity Too Large', |
222 | | - 414: 'Request URI Too Long', |
223 | | - 415: 'Unsupported Media Type', |
224 | | - 416: 'Requested Range Not Satisfiable', |
225 | | - 417: 'Expectation Failed', |
226 | | - 418: "I'm a teapot", # see RFC 2324 |
227 | | - 422: 'Unprocessable Entity', |
228 | | - 423: 'Locked', |
229 | | - 424: 'Failed Dependency', |
230 | | - 426: 'Upgrade Required', |
231 | | - 429: 'Too Many Requests', |
232 | | - 449: 'Retry With', # proprietary MS extension |
233 | | - 451: 'Unavailable For Legal Reasons', |
234 | | - 500: 'Internal Server Error', |
235 | | - 501: 'Not Implemented', |
236 | | - 502: 'Bad Gateway', |
237 | | - 503: 'Service Unavailable', |
238 | | - 504: 'Gateway Timeout', |
239 | | - 505: 'HTTP Version Not Supported', |
240 | | - 507: 'Insufficient Storage', |
241 | | - 510: 'Not Extended' |
| 191 | + 100: _('Continue'), |
| 192 | + 101: _('Switching Protocols'), |
| 193 | + 102: _('Processing'), |
| 194 | + 200: _('OK'), |
| 195 | + 201: _('Created'), |
| 196 | + 202: _('Accepted'), |
| 197 | + 203: _('Non Authoritative Information'), |
| 198 | + 204: _('No Content'), |
| 199 | + 205: _('Reset Content'), |
| 200 | + 206: _('Partial Content'), |
| 201 | + 207: _('Multi Status'), |
| 202 | + 226: _('IM Used'), # see RFC 3229 |
| 203 | + 300: _('Multiple Choices'), |
| 204 | + 301: _('Moved Permanently'), |
| 205 | + 302: _('Found'), |
| 206 | + 303: _('See Other'), |
| 207 | + 304: _('Not Modified'), |
| 208 | + 305: _('Use Proxy'), |
| 209 | + 307: _('Temporary Redirect'), |
| 210 | + 400: _('Bad Request'), |
| 211 | + 401: _('Unauthorized'), |
| 212 | + 402: _('Payment Required'), # unused |
| 213 | + 403: _('Forbidden'), |
| 214 | + 404: _('Not Found'), |
| 215 | + 405: _('Method Not Allowed'), |
| 216 | + 406: _('Not Acceptable'), |
| 217 | + 407: _('Proxy Authentication Required'), |
| 218 | + 408: _('Request Timeout'), |
| 219 | + 409: _('Conflict'), |
| 220 | + 410: _('Gone'), |
| 221 | + 411: _('Length Required'), |
| 222 | + 412: _('Precondition Failed'), |
| 223 | + 413: _('Request Entity Too Large'), |
| 224 | + 414: _('Request URI Too Long'), |
| 225 | + 415: _('Unsupported Media Type'), |
| 226 | + 416: _('Requested Range Not Satisfiable'), |
| 227 | + 417: _('Expectation Failed'), |
| 228 | + 418: _("I'm a teapot"), # see RFC 2324 |
| 229 | + 422: _('Unprocessable Entity'), |
| 230 | + 423: _('Locked'), |
| 231 | + 424: _('Failed Dependency'), |
| 232 | + 426: _('Upgrade Required'), |
| 233 | + 429: _('Too Many Requests'), |
| 234 | + 449: _('Retry With'), # proprietary MS extension |
| 235 | + 451: _('Unavailable For Legal Reasons'), |
| 236 | + 500: _('Internal Server Error'), |
| 237 | + 501: _('Not Implemented'), |
| 238 | + 502: _('Bad Gateway'), |
| 239 | + 503: _('Service Unavailable'), |
| 240 | + 504: _('Gateway Timeout'), |
| 241 | + 505: _('HTTP Version Not Supported'), |
| 242 | + 507: _('Insufficient Storage'), |
| 243 | + 510: _('Not Extended') |
242 | 244 | } |
243 | 245 |
|
244 | 246 | WEBDAV_STATUS_CODES = [207, 422, 423, 424, 507] |
@@ -266,36 +268,36 @@ def http_resource_anchor(method, path): |
266 | 268 | class HTTPResource(ObjectDescription): |
267 | 269 |
|
268 | 270 | doc_field_types = [ |
269 | | - TypedField('parameter', label='Parameters', |
| 271 | + TypedField('parameter', label=_('Parameters'), |
270 | 272 | names=('param', 'parameter', 'arg', 'argument'), |
271 | 273 | typenames=('paramtype', 'type')), |
272 | | - TypedField('jsonparameter', label='JSON Parameters', |
| 274 | + TypedField('jsonparameter', label=_('JSON Parameters'), |
273 | 275 | names=('jsonparameter', 'jsonparam', 'json'), |
274 | 276 | typenames=('jsonparamtype', 'jsontype')), |
275 | | - TypedField('requestjsonobject', label='Request JSON Object', |
| 277 | + TypedField('requestjsonobject', label=_('Request JSON Object'), |
276 | 278 | names=('reqjsonobj', 'reqjson', '<jsonobj', '<json'), |
277 | 279 | typenames=('reqjsonobj', '<jsonobj')), |
278 | | - TypedField('requestjsonarray', label='Request JSON Array of Objects', |
| 280 | + TypedField('requestjsonarray', label=_('Request JSON Array of Objects'), |
279 | 281 | names=('reqjsonarr', '<jsonarr'), |
280 | 282 | typenames=('reqjsonarrtype', '<jsonarrtype')), |
281 | | - TypedField('responsejsonobject', label='Response JSON Object', |
| 283 | + TypedField('responsejsonobject', label=_('Response JSON Object'), |
282 | 284 | names=('resjsonobj', 'resjson', '>jsonobj', '>json'), |
283 | 285 | typenames=('resjsonobj', '>jsonobj')), |
284 | | - TypedField('responsejsonarray', label='Response JSON Array of Objects', |
| 286 | + TypedField('responsejsonarray', label=_('Response JSON Array of Objects'), |
285 | 287 | names=('resjsonarr', '>jsonarr'), |
286 | 288 | typenames=('resjsonarrtype', '>jsonarrtype')), |
287 | | - TypedField('queryparameter', label='Query Parameters', |
| 289 | + TypedField('queryparameter', label=_('Query Parameters'), |
288 | 290 | names=('queryparameter', 'queryparam', 'qparam', 'query'), |
289 | 291 | typenames=('queryparamtype', 'querytype', 'qtype')), |
290 | | - GroupedField('formparameter', label='Form Parameters', |
| 292 | + GroupedField('formparameter', label=_('Form Parameters'), |
291 | 293 | names=('formparameter', 'formparam', 'fparam', 'form')), |
292 | | - GroupedField('requestheader', label='Request Headers', |
| 294 | + GroupedField('requestheader', label=_('Request Headers'), |
293 | 295 | rolename='header', |
294 | 296 | names=('<header', 'reqheader', 'requestheader')), |
295 | | - GroupedField('responseheader', label='Response Headers', |
| 297 | + GroupedField('responseheader', label=_('Response Headers'), |
296 | 298 | rolename='header', |
297 | 299 | names=('>header', 'resheader', 'responseheader')), |
298 | | - GroupedField('statuscode', label='Status Codes', |
| 300 | + GroupedField('statuscode', label=_('Status Codes'), |
299 | 301 | rolename='statuscode', |
300 | 302 | names=('statuscode', 'status', 'code')) |
301 | 303 | ] |
@@ -531,7 +533,7 @@ def result_nodes(self, document, env, node, is_ref): |
531 | 533 | class HTTPIndex(Index): |
532 | 534 |
|
533 | 535 | name = 'routingtable' |
534 | | - localname = 'HTTP Routing Table' |
| 536 | + localname = _('HTTP Routing Table') |
535 | 537 | shortname = 'routing table' |
536 | 538 |
|
537 | 539 | def __init__(self, *args, **kwargs): |
@@ -798,13 +800,17 @@ def setup(app): |
798 | 800 | app.add_domain(HTTPDomain) |
799 | 801 | app.connect('doctree-read', register_routingtable_as_label) |
800 | 802 |
|
| 803 | + package_dir = os.path.abspath(os.path.dirname(__file__)) |
| 804 | + locale_dir = os.path.join(package_dir, 'locale') |
| 805 | + app.add_message_catalog('httpdomain', locale_dir) |
| 806 | + |
801 | 807 | try: |
802 | 808 | get_lexer_by_name('http') |
803 | 809 | except ClassNotFound: |
804 | 810 | app.add_lexer('http', HTTPLexer()) |
805 | 811 | app.add_config_value('http_index_ignore_prefixes', [], None) |
806 | 812 | app.add_config_value('http_index_shortname', 'routing table', True) |
807 | | - app.add_config_value('http_index_localname', 'HTTP Routing Table', True) |
| 813 | + app.add_config_value('http_index_localname', _('HTTP Routing Table'), True) |
808 | 814 | app.add_config_value('http_strict_mode', True, None) |
809 | 815 | app.add_config_value('http_headers_ignore_prefixes', ['X-'], None) |
810 | 816 | return {"parallel_read_safe": True, |
|
0 commit comments