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
b5ad5b71
Commit
b5ad5b71
authored
Apr 02, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pluggable checks (issue #21)
parent
c3d4ab26
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
334 additions
and
168 deletions
+334
-168
docs/admin.rst
docs/admin.rst
+36
-0
docs/config.rst
docs/config.rst
+6
-0
docs/usage.rst
docs/usage.rst
+2
-0
settings.py
settings.py
+18
-0
trans/checks.py
trans/checks.py
+268
-164
trans/models.py
trans/models.py
+4
-4
No files found.
docs/admin.rst
View file @
b5ad5b71
...
...
@@ -142,3 +142,39 @@ The changes are in this mode committed once one of following conditions happen:
* merge from upstream occurs
* import of translation happens
* translation for a language is completed
.. _custom-checks:
Customizing checks
------------------
Weblate comes with wide range of consistency checks (see :ref:`checks`), though
they might not 100% cover all you want to check. The list of performed checks
can be adjusted using :envvar:`CHECK_LIST` and you can also add custom checks.
All you need to do is to subclass :class:`trans.checks.Check`, set few
attributes and implement either ``check`` or ``check_single`` methods (first
one if you want to deal with plurals in your code, the latter one does this for
you). You will find below some examples.
Checking translation text does not contain "foo"
++++++++++++++++++++++++++++++++++++++++++++++++
.. code-block:: python
from trans.checks import Check
from django.utils.translation import ugettext_lazy as _
class FooCheck(Check):
# Used as identifier for check, should be unique
check_id = 'foo'
# Short name used to display failing check
name = _('Foo check')
# Description for failing check
description = _('Your translation is foo')
# Real check code
def check_single(self, source, target, flags, language, unit):
return 'foo' in target
docs/config.rst
View file @
b5ad5b71
...
...
@@ -3,6 +3,12 @@ Configuration
All settings are stored in :file:`settings.py` (as usual for Django).
.. envvar:: CHECK_LIST
List of consistency checks to perform on translation.
.. seealso:: :ref:`checks`, :ref:`custom-checks`
.. envvar:: COMMIT_MESSAGE
Message used on each commit Weblate does.
...
...
docs/usage.rst
View file @
b5ad5b71
...
...
@@ -108,6 +108,8 @@ Machine translation service provided by Microsoft.
http://www.microsofttranslator.com/
.. _checks:
Checks
------
...
...
settings.py
View file @
b5ad5b71
...
...
@@ -263,3 +263,21 @@ LAZY_COMMITS = True
# Where to put Whoosh index
WHOOSH_INDEX
=
os
.
path
.
join
(
WEB_ROOT
,
'whoosh-index'
)
# List of consistency checks
CHECK_LIST
=
(
'trans.checks.SameCheck'
,
'trans.checks.BeginNewlineCheck'
,
'trans.checks.EndNewlineCheck'
,
'trans.checks.EndSpaceCheck'
,
'trans.checks.EndStopCheck'
,
'trans.checks.EndColonCheck'
,
'trans.checks.EndQuestionCheck'
,
'trans.checks.EndExclamationCheck'
,
'trans.checks.PythonFormatCheck'
,
'trans.checks.PHPFormatCheck'
,
'trans.checks.CFormatCheck'
,
'trans.checks.PluralsCheck'
,
'trans.checks.ConsistencyCheck'
,
)
trans/checks.py
View file @
b5ad5b71
This diff is collapsed.
Click to expand it.
trans/models.py
View file @
b5ad5b71
...
...
@@ -616,7 +616,7 @@ class Translation(models.Model):
for
check
in
trans
.
checks
.
CHECKS
:
cnt
=
self
.
unit_set
.
filter_type
(
check
).
count
()
if
cnt
>
0
:
desc
=
trans
.
checks
.
CHECKS
[
check
]
[
2
]
+
(
' (%d)'
%
cnt
)
desc
=
trans
.
checks
.
CHECKS
[
check
]
.
description
+
(
' (%d)'
%
cnt
)
result
.
append
((
check
,
desc
))
return
result
...
...
@@ -850,7 +850,7 @@ class Unit(models.Model):
tgt
=
self
.
get_target_plurals
()
failing
=
[]
for
check
in
trans
.
checks
.
CHECKS
:
if
trans
.
checks
.
CHECKS
[
check
]
[
1
]
(
src
,
tgt
,
self
.
flags
,
self
.
translation
.
language
,
self
):
if
trans
.
checks
.
CHECKS
[
check
]
.
check
(
src
,
tgt
,
self
.
flags
,
self
.
translation
.
language
,
self
):
failing
.
append
(
check
)
for
check
in
self
.
checks
():
...
...
@@ -901,7 +901,7 @@ class Suggestion(models.Model):
unit
.
fuzzy
=
False
unit
.
save_backend
(
request
,
False
)
CHECK_CHOICES
=
[(
x
,
trans
.
checks
.
CHECKS
[
x
]
[
0
]
)
for
x
in
trans
.
checks
.
CHECKS
]
CHECK_CHOICES
=
[(
x
,
trans
.
checks
.
CHECKS
[
x
]
.
name
)
for
x
in
trans
.
checks
.
CHECKS
]
class
Check
(
models
.
Model
):
checksum
=
models
.
CharField
(
max_length
=
40
,
default
=
''
,
blank
=
True
,
db_index
=
True
)
...
...
@@ -923,7 +923,7 @@ class Check(models.Model):
)
def
get_description
(
self
):
return
trans
.
checks
.
CHECKS
[
self
.
check
]
[
2
]
return
trans
.
checks
.
CHECKS
[
self
.
check
]
.
description
def
get_doc_url
(
self
):
return
'http://weblate.readthedocs.org/en/weblate-%s/usage.html#check-%s'
%
(
...
...
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