Commit 8795e17b authored by Michal Čihař's avatar Michal Čihař

Merge remote-tracking branch 'origin/master'

parents f552641c b29bd8d4
......@@ -142,3 +142,70 @@ 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"
++++++++++++++++++++++++++++++++++++++++++++++++
This is pretty simple check which just checks whether translation does not
contain string "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
Checking Czech translation text plurals differ
++++++++++++++++++++++++++++++++++++++++++++++
Check using language information to verify that two plural forms in Czech
language are not same.
.. code-block:: python
from trans.checks import Check
from django.utils.translation import ugettext_lazy as _
class PluralCzechCheck(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(self, sources, targets, flags, language, unit):
if self.is_language(language, ['cs']):
return targets[1] == targets[2]
return False
......@@ -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.
......
......@@ -59,6 +59,13 @@ preferences, translation to these languages will be shown.
Bellow translation can be also shown suggestions from other users, which you
can accept or delete.
Dictionary
----------
Each project can have assigned dictionary for any language. This could be used
for storing terminology for given project, so that translations are consistent.
You can display terms from currently translated string in bottom tabs.
Suggestions
-----------
......@@ -101,6 +108,8 @@ Machine translation service provided by Microsoft.
http://www.microsofttranslator.com/
.. _checks:
Checks
------
......
......@@ -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',
)
This diff is collapsed.
......@@ -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' % (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment