Skip to content
This repository
Browse code

Document custom fixups

  • Loading branch information...
commit bbe2593b363663a341c575d4ba4a0991c503f49e 1 parent c9ac074
Michal Čihař authored May 06, 2013
17  docs/admin.rst
Source Rendered
@@ -588,6 +588,23 @@ languages using ``dictionary`` Python module:
588 588
 You can list own class in :setting:`MACHINE_TRANSLATION_SERVICES` and Weblate
589 589
 will start using that.
590 590
 
  591
+.. _custom-autofix:
  592
+
  593
+Custom automatic fixups
  594
+-----------------------
  595
+
  596
+You can also implement own automatic fixup in addition to standard ones and
  597
+include them in :setting:`AUTOFIX_LIST`.
  598
+
  599
+The automatic fixes are powerful, but can also cause damage, be careful when
  600
+writing one.
  601
+
  602
+For example following automatic fixup would replace every occurence of string
  603
+``foo`` in translation with ``bar``:
  604
+
  605
+.. literalinclude:: ../examples/fix_foo.py
  606
+    :language: python
  607
+
591 608
 .. _custom-checks:
592 609
 
593 610
 Customizing checks
2  docs/config.rst
Source Rendered
@@ -75,6 +75,8 @@ For example you can enable only few of them:
75 75
         'trans.autofixes.chars.ReplaceTrailingDotsWithEllipsis',
76 76
     )
77 77
 
  78
+.. seealso:: :ref:`autofix`, :ref:`custom-autofix`
  79
+
78 80
 .. setting:: BACKGROUND_HOOKS
79 81
 
80 82
 BACKGROUND_HOOKS
35  examples/fix_foo.py
... ...
@@ -0,0 +1,35 @@
  1
+# -*- coding: utf-8 -*-
  2
+#
  3
+# Copyright © 2012 - 2013 Michal Čihař <michal@cihar.com>
  4
+#
  5
+# This file is part of Weblate <http://weblate.org/>
  6
+#
  7
+# This program is free software: you can redistribute it and/or modify
  8
+# it under the terms of the GNU General Public License as published by
  9
+# the Free Software Foundation, either version 3 of the License, or
  10
+# (at your option) any later version.
  11
+#
  12
+# This program is distributed in the hope that it will be useful,
  13
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
  14
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15
+# GNU General Public License for more details.
  16
+#
  17
+# You should have received a copy of the GNU General Public License
  18
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19
+#
  20
+
  21
+from trans.autofixes.base import AutoFix
  22
+from django.utils.translation import ugettext_lazy as _
  23
+
  24
+
  25
+class ReplaceFooWithBar(AutoFix):
  26
+    '''
  27
+    Replaces foo with bar.
  28
+    '''
  29
+
  30
+    name = _('Foobar')
  31
+
  32
+    def fix_single_target(self, target, source, unit):
  33
+        if 'foo' in target:
  34
+            return target.replace('foo', 'bar'), True
  35
+        return target, False

0 notes on commit bbe2593

Please sign in to comment.
Something went wrong with that request. Please try again.