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
eab1282e
Commit
eab1282e
authored
Nov 13, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add check for XML validity (issue #145)
parent
9c16b4bb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
0 deletions
+45
-0
docs/usage.rst
docs/usage.rst
+10
-0
weblate/settings_example.py
weblate/settings_example.py
+1
-0
weblate/trans/checks.py
weblate/trans/checks.py
+34
-0
No files found.
docs/usage.rst
View file @
eab1282e
...
...
@@ -319,6 +319,16 @@ Zero-width space
Translation contains extra zero-width space (<U+200B>) character. This
character is usually inserted by mistake.
.. _check-xml-tags:
XML tags mismatch
~~~~~~~~~~~~~~~~~
XML tags in translation do not match source. This usually means resulting
output will look different. In most cases this is not desired result from
translation, but occasionally it is desired.
.. _check-optional-plural:
Source checks
...
...
weblate/settings_example.py
View file @
eab1282e
...
...
@@ -339,6 +339,7 @@ CHECK_LIST = (
'weblate.trans.checks.NewlineCountingCheck'
,
'weblate.trans.checks.BBCodeCheck'
,
'weblate.trans.checks.ZeroWidthSpaceCheck'
,
'weblate.trans.checks.XMLTagsCheck'
,
'weblate.trans.checks.OptionalPluralCheck'
,
'weblate.trans.checks.EllipsisCheck'
,
)
...
...
weblate/trans/checks.py
View file @
eab1282e
...
...
@@ -21,6 +21,8 @@
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.core.exceptions
import
ImproperlyConfigured
from
django.conf
import
settings
from
django.core.cache
import
cache
from
xml.etree
import
ElementTree
import
weblate
import
re
...
...
@@ -60,6 +62,8 @@ C_PRINTF_MATCH = re.compile('''
BBCODE_MATCH
=
re
.
compile
(
r'\
[(?P<
tag>[^]]*)(?=(@[^]]*)?\
](.*?)
\[\
/(?P=
tag)\
])
', re.MULTILINE)
XML_MATCH = re.compile(r'
<
[
^>
]
+>
')
# Matches (s) not followed by alphanumeric chars or at the end
PLURAL_MATCH = re.compile(r'
\
(
s
\
)(
\
W
|
\
Z
)
')
...
...
@@ -155,6 +159,7 @@ DEFAULT_CHECK_LIST = (
'
weblate
.
trans
.
checks
.
NewlineCountingCheck
',
'
weblate
.
trans
.
checks
.
BBCodeCheck
',
'
weblate
.
trans
.
checks
.
ZeroWidthSpaceCheck
',
'
weblate
.
trans
.
checks
.
XMLTagsCheck
',
'
weblate
.
trans
.
checks
.
OptionalPluralCheck
',
'
weblate
.
trans
.
checks
.
EllipsisCheck
',
)
...
...
@@ -613,6 +618,35 @@ class ZeroWidthSpaceCheck(TargetCheck):
def
check_single
(
self
,
source
,
target
,
flags
,
language
,
unit
):
return
u'
\
u200b
'
in
target
and
not
u'
\
u200b
'
in
source
class
XMLTagsCheck
(
TargetCheck
):
'''
Check whether XML in target matches source.
'''
check_id
=
'xml-tags'
name
=
_
(
'XML tags mismatch'
)
description
=
_
(
'XML tags in translation do not match source'
)
def
check_single
(
self
,
source
,
target
,
flags
,
language
,
unit
):
# Quick check if source looks like XML
if
not
'<'
in
source
or
len
(
XML_MATCH
.
findall
(
source
))
==
0
:
return
False
# Check if source is XML
try
:
source_tree
=
ElementTree
.
fromstring
(
'<weblate>%s</weblate>'
%
source
)
source_tags
=
[
x
.
tag
for
x
in
source_tree
.
iter
()]
except
:
# Source is not valid XML, we give up
return
False
# Check target
try
:
target_tree
=
ElementTree
.
fromstring
(
'<weblate>%s</weblate>'
%
target
)
target_tags
=
[
x
.
tag
for
x
in
target_tree
.
iter
()]
except
:
# Target is not valid XML
return
True
# Compare tags
return
source_tags
!=
target_tags
class
OptionalPluralCheck
(
SourceCheck
):
'''
Check for not used plural form.
...
...
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