Commit 17b329ae authored by Jannis Leidel's avatar Jannis Leidel
Browse files

Fixed #10004 and #12320 -- Enabled the makemessages management command to...

Fixed #10004 and #12320 -- Enabled the makemessages management command to collect comments for translators that start with the "Translators" keyword. Thanks for the report and patches, martinb and Claude Paroz.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14595 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent d7ad02ff
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -196,7 +196,7 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
                    'xgettext -d %s -L Perl %s --keyword=gettext_noop '
                    '--keyword=gettext_lazy --keyword=ngettext_lazy:1,2 '
                    '--keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 '
                    '--from-code UTF-8 -o - "%s"' % (
                    '--from-code UTF-8 --add-comments=Translators -o - "%s"' % (
                        domain, wrap, os.path.join(dirpath, thefile)
                    )
                )
@@ -240,8 +240,9 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
                    '--keyword=ugettext_noop --keyword=ugettext_lazy '
                    '--keyword=ungettext_lazy:1,2 --keyword=pgettext:1c,2 '
                    '--keyword=npgettext:1c,2,3 --keyword=pgettext_lazy:1c,2 '
                    '--keyword=npgettext_lazy:1c,2,3 --from-code UTF-8 -o - '
                    '"%s"' % (domain, wrap, os.path.join(dirpath, thefile))
                    '--keyword=npgettext_lazy:1c,2,3 --from-code UTF-8 '
                    '--add-comments=Translators -o - "%s"' % (
                        domain, wrap, os.path.join(dirpath, thefile))
                )
                msgs, errors = _popen(cmd)
                if errors:
@@ -282,6 +283,8 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
                    raise CommandError("errors happened while running msgmerge\n%s" % errors)
            elif not invoked_for_django:
                msgs = copy_plural_forms(msgs, locale, domain, verbosity)
            msgs = msgs.replace(
                "#. #-#-#-#-#  %s.pot (PACKAGE VERSION)  #-#-#-#-#\n" % domain, "")
            f = open(pofile, 'wb')
            try:
                f.write(msgs)
+5 −1
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ VARIABLE_TAG_START = '{{'
VARIABLE_TAG_END = '}}'
COMMENT_TAG_START = '{#'
COMMENT_TAG_END = '#}'
TRANSLATOR_COMMENT_MARK = 'Translators'
SINGLE_BRACE_START = '{'
SINGLE_BRACE_END = '}'

@@ -237,7 +238,10 @@ class Lexer(object):
            elif token_string.startswith(BLOCK_TAG_START):
                token = Token(TOKEN_BLOCK, token_string[len(BLOCK_TAG_START):-len(BLOCK_TAG_END)].strip())
            elif token_string.startswith(COMMENT_TAG_START):
                token = Token(TOKEN_COMMENT, '')
                content = ''
                if token_string.find(TRANSLATOR_COMMENT_MARK):
                    content = token_string[len(COMMENT_TAG_START):-len(COMMENT_TAG_END)].strip()
                token = Token(TOKEN_COMMENT, content)
        else:
            token = Token(TOKEN_TEXT, token_string)
        return token
+15 −2
Original line number Diff line number Diff line
@@ -427,14 +427,23 @@ def templatize(src):
    does so by translating the Django translation tags into standard gettext
    function invocations.
    """
    from django.template import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
    from django.template import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK, TOKEN_COMMENT
    out = StringIO()
    intrans = False
    inplural = False
    singular = []
    plural = []
    incomment = False
    comment = []
    for t in Lexer(src, None).tokenize():
        if intrans:
        if incomment:
            if t.token_type == TOKEN_BLOCK and t.contents == 'endcomment':
                out.write(' # %s' % ''.join(comment))
                incomment = False
                comment = []
            else:
                comment.append(t.contents)
        elif intrans:
            if t.token_type == TOKEN_BLOCK:
                endbmatch = endblock_re.match(t.contents)
                pluralmatch = plural_re.match(t.contents)
@@ -488,6 +497,8 @@ def templatize(src):
                elif cmatches:
                    for cmatch in cmatches:
                        out.write(' _(%s) ' % cmatch)
                elif t.contents == 'comment':
                    incomment = True
                else:
                    out.write(blankout(t.contents, 'B'))
            elif t.token_type == TOKEN_VAR:
@@ -500,6 +511,8 @@ def templatize(src):
                        out.write(' %s ' % p.split(':',1)[1])
                    else:
                        out.write(blankout(p, 'F'))
            elif t.token_type == TOKEN_COMMENT:
                out.write(' # %s' % t.contents)
            else:
                out.write(blankout(t.contents, 'X'))
    return out.getvalue()
+16 −0
Original line number Diff line number Diff line
@@ -39,6 +39,22 @@ See the :doc:`reference documentation of the app </ref/contrib/staticfiles>`
for more details or learn how to :doc:`manage static files
</howto/static-files>`.

Translation comments
~~~~~~~~~~~~~~~~~~~~

If you would like to give translators hints about a translatable string, you
can add a comment prefixed with the ``Translators`` keyword on the line
preceding the string, e.g.::

    def my_view(request):
        # Translators: This message appears on the home page only
        output = ugettext("Welcome to my site.")

The comment will appear in the resulting .po file and should also be
displayed by most translation tools.

For more information, see :ref:`translator-comments`.

Backwards-incompatible changes in 1.3 alpha 2
=============================================

+7 −3
Original line number Diff line number Diff line
@@ -121,13 +121,17 @@ value, protect, or do nothing.
For more information, see the :attr:`~django.db.models.ForeignKey.on_delete`
documentation.

Contextual markers in translatable strings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Contextual markers and comments for translatable strings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For translation strings with ambiguous meaning, you can now
use the ``pgettext`` function to specify the context of the string.

For more information, see :ref:`contextual-markers`
And if you just want to add some information for translators, you
can also add special translator comments in the source.

For more information, see :ref:`contextual-markers` and
:ref:`translator-comments`.

Everything else
~~~~~~~~~~~~~~~
Loading