mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Enabled makemessages to support several translation directories
Thanks Rémy Hubscher, Ramiro Morales, Unai Zalakain and Tim Graham for the reviews. Also fixes #16084.
This commit is contained in:
parent
9af7e18f35
commit
50a8ab7cd1
13 changed files with 172 additions and 80 deletions
|
@ -8,9 +8,11 @@ import shutil
|
|||
from unittest import SkipTest, skipUnless
|
||||
import warnings
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import management
|
||||
from django.core.management.utils import find_command
|
||||
from django.test import SimpleTestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils._os import upath
|
||||
from django.utils import six
|
||||
|
@ -497,3 +499,47 @@ class MultipleLocaleExtractionTests(ExtractorTests):
|
|||
management.call_command('makemessages', locale=['pt', 'de'], verbosity=0)
|
||||
self.assertTrue(os.path.exists(self.PO_FILE_PT))
|
||||
self.assertTrue(os.path.exists(self.PO_FILE_DE))
|
||||
|
||||
|
||||
class CustomLayoutExtractionTests(ExtractorTests):
|
||||
def setUp(self):
|
||||
self._cwd = os.getcwd()
|
||||
self.test_dir = os.path.join(os.path.dirname(upath(__file__)), 'project_dir')
|
||||
|
||||
def test_no_locale_raises(self):
|
||||
os.chdir(self.test_dir)
|
||||
with six.assertRaisesRegex(self, management.CommandError,
|
||||
"Unable to find a locale path to store translations for file"):
|
||||
management.call_command('makemessages', locale=LOCALE, verbosity=0)
|
||||
|
||||
@override_settings(
|
||||
LOCALE_PATHS=(os.path.join(
|
||||
os.path.dirname(upath(__file__)), 'project_dir', 'project_locale'),)
|
||||
)
|
||||
def test_project_locale_paths(self):
|
||||
"""
|
||||
Test that:
|
||||
* translations for an app containing a locale folder are stored in that folder
|
||||
* translations outside of that app are in LOCALE_PATHS[0]
|
||||
"""
|
||||
os.chdir(self.test_dir)
|
||||
self.addCleanup(shutil.rmtree,
|
||||
os.path.join(settings.LOCALE_PATHS[0], LOCALE), True)
|
||||
self.addCleanup(shutil.rmtree,
|
||||
os.path.join(self.test_dir, 'app_with_locale', 'locale', LOCALE), True)
|
||||
|
||||
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
||||
project_de_locale = os.path.join(
|
||||
self.test_dir, 'project_locale', 'de', 'LC_MESSAGES', 'django.po')
|
||||
app_de_locale = os.path.join(
|
||||
self.test_dir, 'app_with_locale', 'locale', 'de', 'LC_MESSAGES', 'django.po')
|
||||
self.assertTrue(os.path.exists(project_de_locale))
|
||||
self.assertTrue(os.path.exists(app_de_locale))
|
||||
|
||||
with open(project_de_locale, 'r') as fp:
|
||||
po_contents = force_text(fp.read())
|
||||
self.assertMsgId('This app has no locale directory', po_contents)
|
||||
self.assertMsgId('This is a project-level string', po_contents)
|
||||
with open(app_de_locale, 'r') as fp:
|
||||
po_contents = force_text(fp.read())
|
||||
self.assertMsgId('This app has a locale directory', po_contents)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue