diff options
| author | Matthew Somerville <matthew-github@dracos.co.uk> | 2015-04-16 12:55:37 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-06-04 21:02:02 -0400 |
| commit | 40f0a84cb151669313faadf857aaddd18d39aaeb (patch) | |
| tree | fcfa0aea3ee68d0c17dfa91679e0d6b6fb14af81 | |
| parent | 7bda2d8ebc7833747363ac837fecb6535c817dcd (diff) | |
Fixed #24159 -- Made compilemessages run across all apps.
Updated the command to match the documentation, which states it
runs over all .po files.
| -rw-r--r-- | AUTHORS | 2 | ||||
| -rw-r--r-- | django/core/management/commands/compilemessages.py | 6 | ||||
| -rw-r--r-- | docs/ref/django-admin.txt | 5 | ||||
| -rw-r--r-- | docs/releases/1.9.txt | 4 | ||||
| -rw-r--r-- | docs/topics/i18n/translation.txt | 5 | ||||
| -rw-r--r-- | tests/i18n/commands/app_with_locale/locale/ru/LC_MESSAGES/django.po | 28 | ||||
| -rw-r--r-- | tests/i18n/test_compilation.py | 23 |
7 files changed, 68 insertions, 5 deletions
@@ -462,7 +462,7 @@ answer newbie questions, and generally made Django that much better: Matt Deacalion Stevens <matt@dirtymonkey.co.uk> Matt Dennenbaum Matthew Flanagan <http://wadofstuff.blogspot.com> - Matthew Somerville <matthew-github@dracos.co.uk> + Matthew Somerville <matthew-django@dracos.co.uk> Matthew Tretter <m@tthewwithanm.com> Matthias Kestenholz <mk@406.ch> Matthias Pronk <django@masida.nl> diff --git a/django/core/management/commands/compilemessages.py b/django/core/management/commands/compilemessages.py index f4b45d72ff..1901819d15 100644 --- a/django/core/management/commands/compilemessages.py +++ b/django/core/management/commands/compilemessages.py @@ -61,6 +61,12 @@ class Command(BaseCommand): from django.conf import settings basedirs.extend(upath(path) for path in settings.LOCALE_PATHS) + # Walk entire tree, looking for locale directories + for dirpath, dirnames, filenames in os.walk('.', topdown=True): + for dirname in dirnames: + if dirname == 'locale': + basedirs.append(os.path.join(dirpath, dirname)) + # Gather existing directories. basedirs = set(map(os.path.abspath, filter(os.path.isdir, basedirs))) diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index c76ffc4ba9..37154365ff 100644 --- a/docs/ref/django-admin.txt +++ b/docs/ref/django-admin.txt @@ -161,6 +161,11 @@ are excluded. You can pass ``--use-fuzzy`` option (or ``-f``) to include fuzzy translations into compiled files. +.. versionchanged:: 1.9 + + ``compilemessages`` now matches the operation of :djadmin:`makemessages`, + scanning the project tree for ``.po`` files to compile. + .. versionchanged:: 1.8 Added ``--exclude`` and ``--use-fuzzy`` options. diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt index 793e26ffa3..4047785ef1 100644 --- a/docs/releases/1.9.txt +++ b/docs/releases/1.9.txt @@ -193,6 +193,10 @@ Internationalization :ttag:`get_language_info` template tag. Also added a corresponding template filter: :tfilter:`language_name_translated`. +* You can now run :djadmin:`compilemessages` from the root directory of your + project and it will find all the app message files that were created by + :djadmin:`makemessages`. + Management Commands ^^^^^^^^^^^^^^^^^^^ diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt index d3f68d2ca5..8e32f71bdc 100644 --- a/docs/topics/i18n/translation.txt +++ b/docs/topics/i18n/translation.txt @@ -1583,6 +1583,11 @@ which you ran :djadmin:`django-admin makemessages <makemessages>`, run That's it. Your translations are ready for use. +.. versionchanged:: 1.9 + + ``compilemessages`` now matches the operation of :djadmin:`makemessages`, + scanning the project tree for ``.po`` files to compile. + .. admonition:: Working on Windows? If you're using Windows and need to install the GNU gettext utilities so diff --git a/tests/i18n/commands/app_with_locale/locale/ru/LC_MESSAGES/django.po b/tests/i18n/commands/app_with_locale/locale/ru/LC_MESSAGES/django.po new file mode 100644 index 0000000000..ae23e448a3 --- /dev/null +++ b/tests/i18n/commands/app_with_locale/locale/ru/LC_MESSAGES/django.po @@ -0,0 +1,28 @@ +# 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: 2013-03-30 12:51+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" + +# +msgid "Lenin" +msgstr "Ленин" + +#, fuzzy +msgid "Vodka" +msgstr "Водка" diff --git a/tests/i18n/test_compilation.py b/tests/i18n/test_compilation.py index 682885bec8..df2911868e 100644 --- a/tests/i18n/test_compilation.py +++ b/tests/i18n/test_compilation.py @@ -192,14 +192,21 @@ class CompilationErrorHandling(MessageCompilationTests): call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO()) -class FuzzyTranslationTest(MessageCompilationTests): - +class ProjectAndAppTests(MessageCompilationTests): LOCALE = 'ru' - MO_FILE = 'locale/%s/LC_MESSAGES/django.mo' % LOCALE + PROJECT_MO_FILE = 'locale/%s/LC_MESSAGES/django.mo' % LOCALE + APP_MO_FILE = 'app_with_locale/locale/%s/LC_MESSAGES/django.mo' % LOCALE + + def setUp(self): + super(ProjectAndAppTests, self).setUp() + self.addCleanup(self.rmfile, os.path.join(self.test_dir, self.PROJECT_MO_FILE)) + self.addCleanup(self.rmfile, os.path.join(self.test_dir, self.APP_MO_FILE)) + + +class FuzzyTranslationTest(ProjectAndAppTests): def setUp(self): super(FuzzyTranslationTest, self).setUp() - self.addCleanup(self.rmfile, os.path.join(self.test_dir, self.MO_FILE)) gettext_module._translations = {} # flush cache or test will be useless def test_nofuzzy_compiling(self): @@ -215,3 +222,11 @@ class FuzzyTranslationTest(MessageCompilationTests): with translation.override(self.LOCALE): self.assertEqual(ugettext('Lenin'), force_text('Ленин')) self.assertEqual(ugettext('Vodka'), force_text('Водка')) + + +class AppCompilationTest(ProjectAndAppTests): + + def test_app_locale_compiled(self): + call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO()) + self.assertTrue(os.path.exists(self.PROJECT_MO_FILE)) + self.assertTrue(os.path.exists(self.APP_MO_FILE)) |
