Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ answer newbie questions, and generally made Django that much better:
Michal Chruszcz <troll@pld-linux.org>
michal@plovarna.cz
Michał Modzelewski <michal.modzelewski@gmail.com>
Michał Pokusa <https://github.com/michalpokusa>
Mihai Damian <yang_damian@yahoo.com>
Mihai Preda <mihai_preda@yahoo.com>
Mikaël Barbero <mikael.barbero nospam at nospam free.fr>
Expand Down
16 changes: 11 additions & 5 deletions django/core/management/commands/makemessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,15 @@ def handle(self, *args, **options):
self.invoked_for_django = True
else:
if self.settings_available:
self.locale_paths.extend(settings.LOCALE_PATHS)
for path in settings.LOCALE_PATHS:
locale_path = os.path.abspath(path)
if locale_path not in self.locale_paths:
self.locale_paths.append(locale_path)
# Allow to run makemessages inside an app dir
if os.path.isdir("locale"):
self.locale_paths.append(os.path.abspath("locale"))
locale_path = os.path.abspath("locale")
if locale_path not in self.locale_paths:
self.locale_paths.append(locale_path)
if self.locale_paths:
self.default_locale_path = self.locale_paths[0]
os.makedirs(self.default_locale_path, exist_ok=True)
Expand Down Expand Up @@ -551,9 +556,10 @@ def find_files(self, root):
self.stdout.write("ignoring directory %s" % dirname)
elif dirname == "locale":
dirnames.remove(dirname)
self.locale_paths.insert(
0, os.path.join(os.path.abspath(dirpath), dirname)
)
locale_dir = os.path.join(os.path.abspath(dirpath), dirname)
if locale_dir in self.locale_paths:
self.locale_paths.remove(locale_dir)
self.locale_paths.insert(0, locale_dir)
for filename in filenames:
file_path = os.path.normpath(os.path.join(dirpath, filename))
file_ext = os.path.splitext(filename)[1]
Expand Down
1 change: 0 additions & 1 deletion django/db/backends/mysql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
"IPAddressField": "char(15)",
"GenericIPAddressField": "char(39)",
"JSONField": "json",
"OneToOneField": "integer",
"PositiveBigIntegerField": "bigint UNSIGNED",
"PositiveIntegerField": "integer UNSIGNED",
"PositiveSmallIntegerField": "smallint UNSIGNED",
Expand Down
1 change: 0 additions & 1 deletion django/db/backends/oracle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
"BigIntegerField": "NUMBER(19)",
"IPAddressField": "VARCHAR2(15)",
"GenericIPAddressField": "VARCHAR2(39)",
"OneToOneField": "NUMBER(11)",
"PositiveBigIntegerField": "NUMBER(19)",
"PositiveIntegerField": "NUMBER(11)",
"PositiveSmallIntegerField": "NUMBER(11)",
Expand Down
1 change: 0 additions & 1 deletion django/db/backends/postgresql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
"IPAddressField": "inet",
"GenericIPAddressField": "inet",
"JSONField": "jsonb",
"OneToOneField": "integer",
"PositiveBigIntegerField": "bigint",
"PositiveIntegerField": "integer",
"PositiveSmallIntegerField": "smallint",
Expand Down
1 change: 0 additions & 1 deletion django/db/backends/sqlite3/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
"IPAddressField": "char(15)",
"GenericIPAddressField": "char(39)",
"JSONField": "text",
"OneToOneField": "integer",
"PositiveBigIntegerField": "bigint unsigned",
"PositiveIntegerField": "integer unsigned",
"PositiveSmallIntegerField": "smallint unsigned",
Expand Down
Empty file.
78 changes: 77 additions & 1 deletion tests/i18n/test_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
from django.core.management import execute_from_command_line
from django.core.management.base import CommandError
from django.core.management.commands.makemessages import Command as MakeMessagesCommand
from django.core.management.commands.makemessages import write_pot_file
from django.core.management.commands.makemessages import (
TranslatableFile,
write_pot_file,
)
from django.core.management.utils import find_command
from django.test import SimpleTestCase, override_settings
from django.test.utils import captured_stderr, captured_stdout
Expand Down Expand Up @@ -600,6 +603,79 @@ def test_pot_charset_header_is_utf8(self):
self.assertIn("Content-Type: text/plain; charset=UTF-8", pot_contents)
self.assertIn("mañana; charset=CHARSET", pot_contents)

def test_no_duplicate_locale_paths(self):
for locale_paths in [
[],
[os.path.join(self.test_dir, "locale")],
[Path(self.test_dir, "locale")],
]:
with self.subTest(locale_paths=locale_paths):
with override_settings(LOCALE_PATHS=locale_paths):
cmd = MakeMessagesCommand()
management.call_command(cmd, locale=["en", "ru"], verbosity=0)
self.assertTrue(
all(isinstance(path, str) for path in cmd.locale_paths)
)
self.assertEqual(len(cmd.locale_paths), len(set(cmd.locale_paths)))

def test_no_duplicate_write_po_file_calls(self):
with mock.patch.object(
MakeMessagesCommand, "write_po_file"
) as mock_write_po_file:
cmd = MakeMessagesCommand()
management.call_command(cmd, locale=["en", "ru"], verbosity=0)
self.assertEqual(
len(mock_write_po_file.call_args_list),
len({call.args for call in mock_write_po_file.call_args_list}),
)

def test_correct_translatable_file_locale_dir(self):

class ReturnTrackingMock(mock.Mock):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.call_return_value_list = []

def __call__(self, *args, **kwargs):
value = super().__call__(*args, **kwargs)
self.call_return_value_list.append(value)
return value

for locale_paths in [
[],
[
os.path.join(self.test_dir, "app_with_locale", "locale"),
],
[
os.path.join(self.test_dir, "locale"),
os.path.join(self.test_dir, "app_with_locale", "locale"),
],
]:
with self.subTest(locale_paths=locale_paths):
with override_settings(LOCALE_PATHS=locale_paths):
cmd = MakeMessagesCommand()
rtm = ReturnTrackingMock(wraps=cmd.find_files)

with mock.patch.object(cmd, "find_files", new=rtm):
management.call_command(cmd, locale=["en", "ru"], verbosity=0)
self.assertEqual(len(rtm.call_args_list), 1)
self.assertEqual(len(rtm.call_return_value_list), 1)

for tf in rtm.call_return_value_list[0]:
self.assertIsInstance(tf, TranslatableFile)
abs_file_path = os.path.abspath(
os.path.join(self.test_dir, tf.dirpath, tf.file)
)
max_common_path = max(
[
os.path.commonpath([abs_file_path, locale_path])
for locale_path in cmd.locale_paths
],
key=len,
)
correct_locale_dir = os.path.join(max_common_path, "locale")
self.assertEqual(tf.locale_dir, correct_locale_dir)


class JavaScriptExtractorTests(ExtractorTests):
PO_FILE = "locale/%s/LC_MESSAGES/djangojs.po" % LOCALE
Expand Down
Loading