Skip to content

Commit e1e8d89

Browse files
committed
Fix html5lib#85: remove localization of error messages.
It doesn't make sense to localize error messages, given they are purely technical in content.
1 parent f1176e1 commit e1e8d89

File tree

7 files changed

+184
-203
lines changed

7 files changed

+184
-203
lines changed

html5lib/constants.py

Lines changed: 153 additions & 155 deletions
Large diffs are not rendered by default.

html5lib/filters/lint.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
from __future__ import absolute_import, division, unicode_literals
22

3-
from gettext import gettext
4-
_ = gettext
5-
63
from . import _base
74
from ..constants import cdataElements, rcdataElements, voidElements
85

@@ -23,24 +20,24 @@ def __iter__(self):
2320
if type in ("StartTag", "EmptyTag"):
2421
name = token["name"]
2522
if contentModelFlag != "PCDATA":
26-
raise LintError(_("StartTag not in PCDATA content model flag: %(tag)s") % {"tag": name})
23+
raise LintError("StartTag not in PCDATA content model flag: %(tag)s" % {"tag": name})
2724
if not isinstance(name, str):
28-
raise LintError(_("Tag name is not a string: %(tag)r") % {"tag": name})
25+
raise LintError("Tag name is not a string: %(tag)r" % {"tag": name})
2926
if not name:
30-
raise LintError(_("Empty tag name"))
27+
raise LintError("Empty tag name")
3128
if type == "StartTag" and name in voidElements:
32-
raise LintError(_("Void element reported as StartTag token: %(tag)s") % {"tag": name})
29+
raise LintError("Void element reported as StartTag token: %(tag)s" % {"tag": name})
3330
elif type == "EmptyTag" and name not in voidElements:
34-
raise LintError(_("Non-void element reported as EmptyTag token: %(tag)s") % {"tag": token["name"]})
31+
raise LintError("Non-void element reported as EmptyTag token: %(tag)s" % {"tag": token["name"]})
3532
if type == "StartTag":
3633
open_elements.append(name)
3734
for name, value in token["data"]:
3835
if not isinstance(name, str):
39-
raise LintError(_("Attribute name is not a string: %(name)r") % {"name": name})
36+
raise LintError("Attribute name is not a string: %(name)r" % {"name": name})
4037
if not name:
41-
raise LintError(_("Empty attribute name"))
38+
raise LintError("Empty attribute name")
4239
if not isinstance(value, str):
43-
raise LintError(_("Attribute value is not a string: %(value)r") % {"value": value})
40+
raise LintError("Attribute value is not a string: %(value)r" % {"value": value})
4441
if name in cdataElements:
4542
contentModelFlag = "CDATA"
4643
elif name in rcdataElements:
@@ -51,43 +48,43 @@ def __iter__(self):
5148
elif type == "EndTag":
5249
name = token["name"]
5350
if not isinstance(name, str):
54-
raise LintError(_("Tag name is not a string: %(tag)r") % {"tag": name})
51+
raise LintError("Tag name is not a string: %(tag)r" % {"tag": name})
5552
if not name:
56-
raise LintError(_("Empty tag name"))
53+
raise LintError("Empty tag name")
5754
if name in voidElements:
58-
raise LintError(_("Void element reported as EndTag token: %(tag)s") % {"tag": name})
55+
raise LintError("Void element reported as EndTag token: %(tag)s" % {"tag": name})
5956
start_name = open_elements.pop()
6057
if start_name != name:
61-
raise LintError(_("EndTag (%(end)s) does not match StartTag (%(start)s)") % {"end": name, "start": start_name})
58+
raise LintError("EndTag (%(end)s) does not match StartTag (%(start)s)" % {"end": name, "start": start_name})
6259
contentModelFlag = "PCDATA"
6360

6461
elif type == "Comment":
6562
if contentModelFlag != "PCDATA":
66-
raise LintError(_("Comment not in PCDATA content model flag"))
63+
raise LintError("Comment not in PCDATA content model flag")
6764

6865
elif type in ("Characters", "SpaceCharacters"):
6966
data = token["data"]
7067
if not isinstance(data, str):
71-
raise LintError(_("Attribute name is not a string: %(name)r") % {"name": data})
68+
raise LintError("Attribute name is not a string: %(name)r" % {"name": data})
7269
if not data:
73-
raise LintError(_("%(type)s token with empty data") % {"type": type})
70+
raise LintError("%(type)s token with empty data" % {"type": type})
7471
if type == "SpaceCharacters":
7572
data = data.strip(spaceCharacters)
7673
if data:
77-
raise LintError(_("Non-space character(s) found in SpaceCharacters token: %(token)r") % {"token": data})
74+
raise LintError("Non-space character(s) found in SpaceCharacters token: %(token)r" % {"token": data})
7875

7976
elif type == "Doctype":
8077
name = token["name"]
8178
if contentModelFlag != "PCDATA":
82-
raise LintError(_("Doctype not in PCDATA content model flag: %(name)s") % {"name": name})
79+
raise LintError("Doctype not in PCDATA content model flag: %(name)s" % {"name": name})
8380
if not isinstance(name, str):
84-
raise LintError(_("Tag name is not a string: %(tag)r") % {"tag": name})
81+
raise LintError("Tag name is not a string: %(tag)r" % {"tag": name})
8582
# XXX: what to do with token["data"] ?
8683

8784
elif type in ("ParseError", "SerializeError"):
8885
pass
8986

9087
else:
91-
raise LintError(_("Unknown token type: %(type)s") % {"type": type})
88+
raise LintError("Unknown token type: %(type)s" % {"type": type})
9289

9390
yield token

html5lib/serializer/htmlserializer.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from __future__ import absolute_import, division, unicode_literals
22
from six import text_type
33

4-
import gettext
5-
_ = gettext.gettext
6-
74
try:
85
from functools import reduce
96
except ImportError:
@@ -208,7 +205,7 @@ def serialize(self, treewalker, encoding=None):
208205
if token["systemId"]:
209206
if token["systemId"].find('"') >= 0:
210207
if token["systemId"].find("'") >= 0:
211-
self.serializeError(_("System identifer contains both single and double quote characters"))
208+
self.serializeError("System identifer contains both single and double quote characters")
212209
quote_char = "'"
213210
else:
214211
quote_char = '"'
@@ -220,7 +217,7 @@ def serialize(self, treewalker, encoding=None):
220217
elif type in ("Characters", "SpaceCharacters"):
221218
if type == "SpaceCharacters" or in_cdata:
222219
if in_cdata and token["data"].find("</") >= 0:
223-
self.serializeError(_("Unexpected </ in CDATA"))
220+
self.serializeError("Unexpected </ in CDATA")
224221
yield self.encode(token["data"])
225222
else:
226223
yield self.encode(escape(token["data"]))
@@ -231,7 +228,7 @@ def serialize(self, treewalker, encoding=None):
231228
if name in rcdataElements and not self.escape_rcdata:
232229
in_cdata = True
233230
elif in_cdata:
234-
self.serializeError(_("Unexpected child element of a CDATA element"))
231+
self.serializeError("Unexpected child element of a CDATA element")
235232
for (attr_namespace, attr_name), attr_value in token["data"].items():
236233
# TODO: Add namespace support here
237234
k = attr_name
@@ -279,20 +276,20 @@ def serialize(self, treewalker, encoding=None):
279276
if name in rcdataElements:
280277
in_cdata = False
281278
elif in_cdata:
282-
self.serializeError(_("Unexpected child element of a CDATA element"))
279+
self.serializeError("Unexpected child element of a CDATA element")
283280
yield self.encodeStrict("</%s>" % name)
284281

285282
elif type == "Comment":
286283
data = token["data"]
287284
if data.find("--") >= 0:
288-
self.serializeError(_("Comment contains --"))
285+
self.serializeError("Comment contains --")
289286
yield self.encodeStrict("<!--%s-->" % token["data"])
290287

291288
elif type == "Entity":
292289
name = token["name"]
293290
key = name + ";"
294291
if key not in entities:
295-
self.serializeError(_("Entity %s not recognized" % name))
292+
self.serializeError("Entity %s not recognized" % name)
296293
if self.resolve_entities and key not in xmlEntities:
297294
data = entities[key]
298295
else:

html5lib/treewalkers/_base.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
__all__ = ["DOCUMENT", "DOCTYPE", "TEXT", "ELEMENT", "COMMENT", "ENTITY", "UNKNOWN",
55
"TreeWalker", "NonRecursiveTreeWalker"]
66

7-
import gettext
8-
_ = gettext.gettext
9-
107
from xml.dom import Node
118

129
DOCUMENT = Node.DOCUMENT_NODE
@@ -61,7 +58,7 @@ def emptyTag(self, namespace, name, attrs, hasChildren=False):
6158
"namespace": to_text(namespace),
6259
"data": attrs}
6360
if hasChildren:
64-
yield self.error(_("Void element has children"))
61+
yield self.error("Void element has children")
6562

6663
def startTag(self, namespace, name, attrs):
6764
assert namespace is None or isinstance(namespace, string_types), type(namespace)
@@ -125,7 +122,7 @@ def entity(self, name):
125122
return {"type": "Entity", "name": text_type(name)}
126123

127124
def unknown(self, nodeType):
128-
return self.error(_("Unknown node type: ") + nodeType)
125+
return self.error("Unknown node type: " + nodeType)
129126

130127

131128
class NonRecursiveTreeWalker(TreeWalker):

html5lib/treewalkers/dom.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
from xml.dom import Node
44

5-
import gettext
6-
_ = gettext.gettext
7-
85
from . import _base
96

107

html5lib/treewalkers/etree.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from ordereddict import OrderedDict
88
except ImportError:
99
OrderedDict = dict
10-
import gettext
11-
_ = gettext.gettext
1210

1311
import re
1412

html5lib/treewalkers/lxmletree.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
from lxml import etree
55
from ..treebuilders.etree import tag_regexp
66

7-
from gettext import gettext
8-
_ = gettext
9-
107
from . import _base
118

129
from .. import ihatexml
@@ -130,7 +127,7 @@ def __init__(self, tree):
130127
def getNodeDetails(self, node):
131128
if isinstance(node, tuple): # Text node
132129
node, key = node
133-
assert key in ("text", "tail"), _("Text nodes are text or tail, found %s") % key
130+
assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key
134131
return _base.TEXT, ensure_str(getattr(node, key))
135132

136133
elif isinstance(node, Root):
@@ -169,7 +166,7 @@ def getNodeDetails(self, node):
169166
attrs, len(node) > 0 or node.text)
170167

171168
def getFirstChild(self, node):
172-
assert not isinstance(node, tuple), _("Text nodes have no children")
169+
assert not isinstance(node, tuple), "Text nodes have no children"
173170

174171
assert len(node) or node.text, "Node has no children"
175172
if node.text:
@@ -180,7 +177,7 @@ def getFirstChild(self, node):
180177
def getNextSibling(self, node):
181178
if isinstance(node, tuple): # Text node
182179
node, key = node
183-
assert key in ("text", "tail"), _("Text nodes are text or tail, found %s") % key
180+
assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key
184181
if key == "text":
185182
# XXX: we cannot use a "bool(node) and node[0] or None" construct here
186183
# because node[0] might evaluate to False if it has no child element
@@ -196,7 +193,7 @@ def getNextSibling(self, node):
196193
def getParentNode(self, node):
197194
if isinstance(node, tuple): # Text node
198195
node, key = node
199-
assert key in ("text", "tail"), _("Text nodes are text or tail, found %s") % key
196+
assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key
200197
if key == "text":
201198
return node
202199
# else: fallback to "normal" processing

0 commit comments

Comments
 (0)