== Steps to reproduce
{{{
django-admin startproject mysite
cd mysite/mysite
mkdir locale
}}}
Edit urls.py to add this line at the end:
{{{
_('hello')
}}}
Create messages:
{{{
django-admin makemessages -l de
}}}
Edit urls.py again to add this line at the end:
{{{
pgettext_lazy('context', '')
}}}
Update messages:
{{{
django-admin makemessages
}}}
== Result
The locale/de/django.po file obtained is the following:
{{{
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-01-27 03:50+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <L...@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: urls.py:23
msgid "hello"
msgstr ""
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#: urls.py:24
#, fuzzy
msgctxt "context"
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-01-27 03:49+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <L...@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
}}}
The unexpected behavior is the repetition of some header lines. This seems
to only happen with empty strings in the Python code. While a bit odd, I
think empty strings are valid strings (at least with a context) that may
sometimes need translation.
--
Ticket URL: <https://code.djangoproject.com/ticket/29074>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => Manthan Sharma
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/29074#comment:1>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/29074#comment:2>
Comment (by Hasan Ramezani):
It seems the problem goes from `msgmerge` in `def write_po_file`. I think
merge process destroy the file structure.
--
Ticket URL: <https://code.djangoproject.com/ticket/29074#comment:3>
* status: assigned => closed
* resolution: => wontfix
Comment:
`gettext` does not like when one tries to translate the empty string, as
it has a special meaning in the PO file format. See #23196 for another
case where we had to workaround a similar issue.
In this case, the header duplication is produced by `msgmerge` itself. I'm
of the opinion that we should consider translating an empty string as an
unsupported functionality of the underlying `gettext` library.
--
Ticket URL: <https://code.djangoproject.com/ticket/29074#comment:4>