Ticket #10004: comment-extraction-3.patch

File comment-extraction-3.patch, 4.8 KB (added by Claude Paroz, 14 years ago)

Comment extraction with documentation

  • django/core/management/commands/makemessages.py

     
    196196                    'xgettext -d %s -L Perl %s --keyword=gettext_noop '
    197197                    '--keyword=gettext_lazy --keyword=ngettext_lazy:1,2 '
    198198                    '--keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 '
    199                     '--from-code UTF-8 -o - "%s"' % (
     199                    '--from-code UTF-8 --add-comments=L10n -o - "%s"' % (
    200200                        domain, wrap, os.path.join(dirpath, thefile)
    201201                    )
    202202                )
     
    240240                    '--keyword=ugettext_noop --keyword=ugettext_lazy '
    241241                    '--keyword=ungettext_lazy:1,2 --keyword=pgettext:1c,2 '
    242242                    '--keyword=npgettext:1c,2,3 --keyword=pgettext_lazy:1c,2 '
    243                     '--keyword=npgettext_lazy:1c,2,3 --from-code UTF-8 -o - '
    244                     '"%s"' % (domain, wrap, os.path.join(dirpath, thefile))
     243                    '--keyword=npgettext_lazy:1c,2,3 --from-code UTF-8 '
     244                    '--add-comments=L10n -o - "%s"' % (
     245                        domain, wrap, os.path.join(dirpath, thefile))
    245246                )
    246247                msgs, errors = _popen(cmd)
    247248                if errors:
  • tests/regressiontests/i18n/commands/__init__.py

     
     1from django.utils.translation import ugettext as _
     2
     3# L10n: This comment should be extracted
     4dummy1 = _("This is a translatable string.")
     5
     6# This comment should not be extracted
     7dummy2 = _("This is another translatable string.")
     8
  • tests/regressiontests/i18n/commands/extraction.py

     
    3838        return self.assert_(not re.search('^msgid %s' % msgid, s, re.MULTILINE))
    3939
    4040
    41 class TemplateExtractorTests(ExtractorTests):
     41class BasicExtractorTests(ExtractorTests):
    4242
     43    def test_comments_extractor(self):
     44        os.chdir(self.test_dir)
     45        management.call_command('makemessages', locale=LOCALE, verbosity=0)
     46        self.assert_(os.path.exists(self.PO_FILE))
     47        po_contents = open(self.PO_FILE, 'r').read()
     48        self.assert_('#. L10n: This comment should be extracted' in po_contents)
     49        self.assert_('This comment should not be extracted' not in po_contents)
     50
    4351    def test_templatize(self):
    4452        os.chdir(self.test_dir)
    4553        management.call_command('makemessages', locale=LOCALE, verbosity=0)
  • docs/topics/i18n/internationalization.txt

     
    100100have more than a single parameter. If you used positional interpolation,
    101101translations wouldn't be able to reorder placeholder text.
    102102
     103.. _translator-comments:
     104
     105Comments for translators
     106------------------------
     107
     108.. versionadded:: 1.3
     109
     110If you would like to give translators any hint about a translatable string, you
     111can add a comment prefixed with the ``L10n`` keyword on the line just before the
     112string marked for translation:
     113
     114    def my_view(request):
     115        # L10n: This message appears on the home page only
     116        output = ugettext("Welcome to my site.")
     117
     118The comment will then appear in the resulting .po file and should also be
     119displayed by most translation tools.
     120
    103121Marking strings as no-op
    104122------------------------
    105123
  • docs/releases/1.3.txt

     
    8686
    8787For more information, see :ref:`transaction-management-functions`.
    8888
    89 Contextual markers in translatable strings
    90 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     89Contextual markers and comments for translatable strings
     90~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    9191
    9292For translation strings with ambiguous meaning, you can now
    9393use the ``pgettext`` function to specify the context of the string.
    9494
    95 For more information, see :ref:`contextual-markers`
     95And if you just want to add some information aimed at translators, you
     96can also add special translator comments in the source.
    9697
     98For more information, see :ref:`contextual-markers` and :ref:`translator-comments`.
     99
    97100Everything else
    98101~~~~~~~~~~~~~~~
    99102
Back to Top