Commit bbe2593b authored by Michal Čihař's avatar Michal Čihař

Document custom fixups

parent c9ac0740
......@@ -588,6 +588,23 @@ languages using ``dictionary`` Python module:
You can list own class in :setting:`MACHINE_TRANSLATION_SERVICES` and Weblate
will start using that.
.. _custom-autofix:
Custom automatic fixups
-----------------------
You can also implement own automatic fixup in addition to standard ones and
include them in :setting:`AUTOFIX_LIST`.
The automatic fixes are powerful, but can also cause damage, be careful when
writing one.
For example following automatic fixup would replace every occurence of string
``foo`` in translation with ``bar``:
.. literalinclude:: ../examples/fix_foo.py
:language: python
.. _custom-checks:
Customizing checks
......
......@@ -75,6 +75,8 @@ For example you can enable only few of them:
'trans.autofixes.chars.ReplaceTrailingDotsWithEllipsis',
)
.. seealso:: :ref:`autofix`, :ref:`custom-autofix`
.. setting:: BACKGROUND_HOOKS
BACKGROUND_HOOKS
......
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2013 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from trans.autofixes.base import AutoFix
from django.utils.translation import ugettext_lazy as _
class ReplaceFooWithBar(AutoFix):
'''
Replaces foo with bar.
'''
name = _('Foobar')
def fix_single_target(self, target, source, unit):
if 'foo' in target:
return target.replace('foo', 'bar'), True
return target, False
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