Permalink
Browse files

Document custom fixups

  • Loading branch information...
1 parent c9ac074 commit bbe2593b363663a341c575d4ba4a0991c503f49e @nijel committed May 6, 2013
Showing with 54 additions and 0 deletions.
  1. +17 −0 docs/admin.rst
  2. +2 −0 docs/config.rst
  3. +35 −0 examples/fix_foo.py
View
17 docs/admin.rst
@@ -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
View
2 docs/config.rst
@@ -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
View
35 examples/fix_foo.py
@@ -0,0 +1,35 @@
+# -*- 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

0 comments on commit bbe2593

Please sign in to comment.