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
03a9715c
Commit
03a9715c
authored
Jan 25, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move logic out of presentation code
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
eadde14c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
24 deletions
+33
-24
weblate/trans/checks/__init__.py
weblate/trans/checks/__init__.py
+31
-0
weblate/trans/templatetags/translations.py
weblate/trans/templatetags/translations.py
+2
-24
No files found.
weblate/trans/checks/__init__.py
View file @
03a9715c
...
...
@@ -21,6 +21,37 @@
from
weblate
import
appsettings
from
weblate.trans.util
import
load_class
def
highlight_string
(
source
,
unit
):
"""Returns highlights for a string"""
if
unit
is
None
:
return
[]
highlights
=
[]
for
check
in
CHECKS
:
if
not
CHECKS
[
check
].
target
:
continue
highlights
+=
CHECKS
[
check
].
check_highlight
(
source
,
unit
)
# Sort by order in string
highlights
.
sort
(
key
=
lambda
x
:
x
[
0
])
# Remove overlapping ones
for
hl_idx
in
xrange
(
0
,
len
(
highlights
)):
if
hl_idx
>=
len
(
highlights
):
break
elref
=
highlights
[
hl_idx
]
for
hl_idx_next
in
xrange
(
hl_idx
+
1
,
len
(
highlights
)):
if
hl_idx_next
>=
len
(
highlights
):
break
eltest
=
highlights
[
hl_idx_next
]
if
eltest
[
0
]
>=
elref
[
0
]
and
eltest
[
0
]
<
elref
[
1
]:
highlights
.
pop
(
hl_idx_next
)
elif
eltest
[
0
]
>
elref
[
1
]:
break
return
highlights
# Initialize checks list
CHECKS
=
{}
for
path
in
appsettings
.
CHECK_LIST
:
...
...
weblate/trans/templatetags/translations.py
View file @
03a9715c
...
...
@@ -41,7 +41,7 @@ from weblate.lang.models import Language
from
weblate.trans.models
import
(
Project
,
SubProject
,
Dictionary
,
Advertisement
,
WhiteboardMessage
)
from
weblate.trans.checks
import
CHECKS
from
weblate.trans.checks
import
CHECKS
,
highlight_string
register
=
template
.
Library
()
...
...
@@ -86,30 +86,8 @@ def fmt_check_highlights(value, unit):
"""Formats check highlights"""
if
unit
is
None
:
return
[]
# Find all checks highlight
highlights
=
[]
for
check
in
CHECKS
:
if
not
CHECKS
[
check
].
target
:
continue
highlights
+=
CHECKS
[
check
].
check_highlight
(
value
,
unit
)
#Sort by order in string
if
highlights
:
highlights
.
sort
(
key
=
lambda
tup
:
tup
[
0
])
#remove probelmatics ones (overlapping or one inside another)
for
hl_idx
in
xrange
(
0
,
len
(
highlights
)):
if
hl_idx
>=
len
(
highlights
):
break
elref
=
highlights
[
hl_idx
]
for
hl_idx_next
in
xrange
(
hl_idx
+
1
,
len
(
highlights
)):
if
hl_idx_next
>=
len
(
highlights
):
break
eltest
=
highlights
[
hl_idx_next
]
if
eltest
[
0
]
>=
elref
[
0
]
and
eltest
[
0
]
<
elref
[
1
]:
highlights
.
pop
(
hl_idx_next
)
elif
eltest
[
0
]
>
elref
[
1
]:
break
#then transform highlights to escaped html
highlights
=
[(
h
[
0
],
h
[
1
],
escape
(
force_text
(
h
[
2
])))
for
h
in
highlight
s
]
highlights
=
[(
h
[
0
],
h
[
1
],
escape
(
force_text
(
h
[
2
])))
for
h
in
highlight
_string
(
value
,
unit
)
]
return
highlights
...
...
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