Fixed #6106 -- Prevented makemessages from changing .po files when up to date.
Co-authored-by: Daniyal Abbasi <abbasi.daniyal98@gmail.com>
This commit is contained in:
parent
0b95a96ee1
commit
4bfe8c0eec
|
@ -4,6 +4,7 @@ import re
|
||||||
import sys
|
import sys
|
||||||
from functools import total_ordering
|
from functools import total_ordering
|
||||||
from itertools import dropwhile
|
from itertools import dropwhile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import django
|
import django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -208,7 +209,7 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
requires_system_checks = []
|
requires_system_checks = []
|
||||||
|
|
||||||
msgmerge_options = ['-q', '--previous']
|
msgmerge_options = ['-q', '--backup=none', '--previous', '--update']
|
||||||
msguniq_options = ['--to-code=utf-8']
|
msguniq_options = ['--to-code=utf-8']
|
||||||
msgattrib_options = ['--no-obsolete']
|
msgattrib_options = ['--no-obsolete']
|
||||||
xgettext_options = ['--from-code=UTF-8', '--add-comments=Translators']
|
xgettext_options = ['--from-code=UTF-8', '--add-comments=Translators']
|
||||||
|
@ -615,13 +616,14 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
if os.path.exists(pofile):
|
if os.path.exists(pofile):
|
||||||
args = ['msgmerge'] + self.msgmerge_options + [pofile, potfile]
|
args = ['msgmerge'] + self.msgmerge_options + [pofile, potfile]
|
||||||
msgs, errors, status = popen_wrapper(args)
|
_, errors, status = popen_wrapper(args)
|
||||||
if errors:
|
if errors:
|
||||||
if status != STATUS_OK:
|
if status != STATUS_OK:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
"errors happened while running msgmerge\n%s" % errors)
|
"errors happened while running msgmerge\n%s" % errors)
|
||||||
elif self.verbosity > 0:
|
elif self.verbosity > 0:
|
||||||
self.stdout.write(errors)
|
self.stdout.write(errors)
|
||||||
|
msgs = Path(pofile).read_text(encoding='utf-8')
|
||||||
else:
|
else:
|
||||||
with open(potfile, encoding='utf-8') as fp:
|
with open(potfile, encoding='utf-8') as fp:
|
||||||
msgs = fp.read()
|
msgs = fp.read()
|
||||||
|
|
|
@ -804,3 +804,37 @@ class NoSettingsExtractionTests(AdminScriptTestCase):
|
||||||
out, err = self.run_django_admin(['makemessages', '-l', 'en', '-v', '0'])
|
out, err = self.run_django_admin(['makemessages', '-l', 'en', '-v', '0'])
|
||||||
self.assertNoOutput(err)
|
self.assertNoOutput(err)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
|
|
||||||
|
|
||||||
|
class UnchangedPoExtractionTests(ExtractorTests):
|
||||||
|
work_subdir = 'unchanged'
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
po_file = Path(self.PO_FILE)
|
||||||
|
po_file_tmp = Path(self.PO_FILE + '.tmp')
|
||||||
|
if os.name == 'nt':
|
||||||
|
# msgmerge outputs Windows style paths on Windows.
|
||||||
|
po_contents = po_file_tmp.read_text().replace(
|
||||||
|
'#: __init__.py',
|
||||||
|
'#: .\\__init__.py',
|
||||||
|
)
|
||||||
|
po_file.write_text(po_contents)
|
||||||
|
else:
|
||||||
|
po_file_tmp.rename(po_file)
|
||||||
|
self.original_po_contents = po_file.read_text()
|
||||||
|
|
||||||
|
def test_po_remains_unchanged(self):
|
||||||
|
"""PO files are unchanged unless there are new changes."""
|
||||||
|
_, po_contents = self._run_makemessages()
|
||||||
|
self.assertEqual(po_contents, self.original_po_contents)
|
||||||
|
|
||||||
|
def test_po_changed_with_new_strings(self):
|
||||||
|
"""PO files are updated when new changes are detected."""
|
||||||
|
Path('models.py.tmp').rename('models.py')
|
||||||
|
_, po_contents = self._run_makemessages()
|
||||||
|
self.assertNotEqual(po_contents, self.original_po_contents)
|
||||||
|
self.assertMsgId(
|
||||||
|
'This is a hitherto undiscovered translatable string.',
|
||||||
|
po_contents,
|
||||||
|
)
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
string1 = _('This is a translatable string.')
|
||||||
|
string2 = _('This is another translatable string.')
|
|
@ -0,0 +1,26 @@
|
||||||
|
# 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: 2014-04-25 15:39-0500\n"
|
||||||
|
"PO-Revision-Date: 2014-05-25 15:39-0500\n"
|
||||||
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
"Language: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
|
||||||
|
#: __init__.py:3
|
||||||
|
msgid "This is a translatable string."
|
||||||
|
msgstr "And this has been translated."
|
||||||
|
|
||||||
|
#: __init__.py:4
|
||||||
|
msgid "This is another translatable string."
|
||||||
|
msgstr "And this also has been translated."
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
string3 = _('This is a hitherto undiscovered translatable string.')
|
Loading…
Reference in New Issue