diff --git a/AUTHORS b/AUTHORS index 8a49df0472e..73cf6441dae 100644 --- a/AUTHORS +++ b/AUTHORS @@ -462,7 +462,7 @@ answer newbie questions, and generally made Django that much better: Matt Deacalion Stevens Matt Dennenbaum Matthew Flanagan - Matthew Somerville + Matthew Somerville Matthew Tretter Matthias Kestenholz Matthias Pronk diff --git a/django/core/management/commands/compilemessages.py b/django/core/management/commands/compilemessages.py index f4b45d72ff3..1901819d156 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 c76ffc4ba9f..37154365ff4 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 793e26ffa31..4047785ef11 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 d3f68d2ca56..8e32f71bdcf 100644 --- a/docs/topics/i18n/translation.txt +++ b/docs/topics/i18n/translation.txt @@ -1583,6 +1583,11 @@ which you ran :djadmin:`django-admin 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 00000000000..ae23e448a37 --- /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 , 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 \n" +"Language-Team: LANGUAGE \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 682885bec86..df2911868e2 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))