summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-11-30 10:53:08 +0100
committerClaude Paroz <claude@2xlibre.net>2013-11-30 11:00:23 +0100
commit50a8ab7cd1e611e6422a148becaec02218577d67 (patch)
tree180cc283c7f700a343733df3f1b2d88a79a3d7d0 /tests
parent9af7e18f3579df18625b9eda70735790f23aeb96 (diff)
Enabled makemessages to support several translation directories
Thanks Rémy Hubscher, Ramiro Morales, Unai Zalakain and Tim Graham for the reviews. Also fixes #16084.
Diffstat (limited to 'tests')
-rw-r--r--tests/i18n/project_dir/__init__.py4
-rw-r--r--tests/i18n/project_dir/app_no_locale/__init__.py0
-rw-r--r--tests/i18n/project_dir/app_no_locale/models.py3
-rw-r--r--tests/i18n/project_dir/app_with_locale/__init__.py0
-rw-r--r--tests/i18n/project_dir/app_with_locale/locale/.gitkeep0
-rw-r--r--tests/i18n/project_dir/app_with_locale/models.py3
-rw-r--r--tests/i18n/project_dir/project_locale/.gitkeep0
-rw-r--r--tests/i18n/test_extraction.py46
8 files changed, 56 insertions, 0 deletions
diff --git a/tests/i18n/project_dir/__init__.py b/tests/i18n/project_dir/__init__.py
new file mode 100644
index 0000000000..b32b258e37
--- /dev/null
+++ b/tests/i18n/project_dir/__init__.py
@@ -0,0 +1,4 @@
+# Sample project used by test_extraction.CustomLayoutExtractionTests
+from django.utils.translation import ugettext as _
+
+string = _("This is a project-level string")
diff --git a/tests/i18n/project_dir/app_no_locale/__init__.py b/tests/i18n/project_dir/app_no_locale/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/i18n/project_dir/app_no_locale/__init__.py
diff --git a/tests/i18n/project_dir/app_no_locale/models.py b/tests/i18n/project_dir/app_no_locale/models.py
new file mode 100644
index 0000000000..06dfbaa5d4
--- /dev/null
+++ b/tests/i18n/project_dir/app_no_locale/models.py
@@ -0,0 +1,3 @@
+from django.utils.translation import ugettext as _
+
+string = _("This app has no locale directory")
diff --git a/tests/i18n/project_dir/app_with_locale/__init__.py b/tests/i18n/project_dir/app_with_locale/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/i18n/project_dir/app_with_locale/__init__.py
diff --git a/tests/i18n/project_dir/app_with_locale/locale/.gitkeep b/tests/i18n/project_dir/app_with_locale/locale/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/i18n/project_dir/app_with_locale/locale/.gitkeep
diff --git a/tests/i18n/project_dir/app_with_locale/models.py b/tests/i18n/project_dir/app_with_locale/models.py
new file mode 100644
index 0000000000..ab35d5002a
--- /dev/null
+++ b/tests/i18n/project_dir/app_with_locale/models.py
@@ -0,0 +1,3 @@
+from django.utils.translation import ugettext as _
+
+string = _("This app has a locale directory")
diff --git a/tests/i18n/project_dir/project_locale/.gitkeep b/tests/i18n/project_dir/project_locale/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/i18n/project_dir/project_locale/.gitkeep
diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py
index d2af8b0cc8..1637e29f67 100644
--- a/tests/i18n/test_extraction.py
+++ b/tests/i18n/test_extraction.py
@@ -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)