Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
59418ef8
Commit
59418ef8
authored
Nov 21, 2012
by
Weblate
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
58a74e62
2eaf8cd1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
+18
-3
weblate/trans/checks.py
weblate/trans/checks.py
+18
-3
No files found.
weblate/trans/checks.py
View file @
59418ef8
...
...
@@ -63,6 +63,7 @@ C_PRINTF_MATCH = re.compile('''
BBCODE_MATCH
=
re
.
compile
(
r'\
[(?P<
tag>[^]]*)(?=(@[^]]*)?\
](.*?)
\[\
/(?P=
tag)\
])
', re.MULTILINE)
XML_MATCH = re.compile(r'
<
[
^>
]
+>
')
XML_ENTITY_MATCH = re.compile(r'
&
#?\w+;')
# Matches (s) not followed by alphanumeric chars or at the end
PLURAL_MATCH
=
re
.
compile
(
r'\
(s
\)(\
W|
\Z)'
)
...
...
@@ -662,9 +663,23 @@ class XMLTagsCheck(TargetCheck):
name
=
_
(
'XML tags mismatch'
)
description
=
_
(
'XML tags in translation do not match source'
)
def
strip_entities
(
self
,
text
):
'''
Strips all HTML entities (we don't care about them).
'''
return
XML_ENTITY_MATCH
.
sub
(
''
,
text
)
def
parse_xml
(
self
,
text
):
'''
Wrapper for parsing XML.
'''
text
=
self
.
strip_entities
(
text
.
encode
(
'utf-8'
))
return
ElementTree
.
fromstring
(
'<weblate>%s</weblate>'
%
text
)
def
check_single
(
self
,
source
,
target
,
flags
,
language
,
unit
):
# Try getting source string data from cache
source_tags
=
self
.
get_cache
(
unit
)
source_tags
=
None
#
self.get_cache(unit)
# Source is not XML
if
source_tags
==
False
:
...
...
@@ -678,7 +693,7 @@ class XMLTagsCheck(TargetCheck):
return
False
# Check if source is XML
try
:
source_tree
=
ElementTree
.
fromstring
(
'<weblate>%s</weblate>'
%
source
.
encode
(
'utf-8'
)
)
source_tree
=
self
.
parse_xml
(
source
)
source_tags
=
[
x
.
tag
for
x
in
source_tree
.
iter
()]
self
.
set_cache
(
unit
,
source_tags
)
except
:
...
...
@@ -688,7 +703,7 @@ class XMLTagsCheck(TargetCheck):
# Check target
try
:
target_tree
=
ElementTree
.
fromstring
(
'<weblate>%s</weblate>'
%
target
.
encode
(
'utf-8'
)
)
target_tree
=
self
.
parse_xml
(
target
)
target_tags
=
[
x
.
tag
for
x
in
target_tree
.
iter
()]
except
:
# Target is not valid XML
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment