Fixed #24159 -- Made compilemessages run across all apps.

Updated the command to match the documentation, which states it
runs over all .po files.
This commit is contained in:
Matthew Somerville 2015-04-16 12:55:37 +01:00 committed by Tim Graham
parent 7bda2d8ebc
commit 40f0a84cb1
7 changed files with 68 additions and 5 deletions

View File

@ -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>

View File

@ -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)))

View File

@ -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.

View File

@ -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
^^^^^^^^^^^^^^^^^^^

View File

@ -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

View File

@ -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 "Водка"

View File

@ -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))