From 37f4488273c93928f2d6e89fda3c0aefcd42db43 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 22 Feb 2013 11:54:22 +0100 Subject: [PATCH 1/1] Add management command for localizing contrib apps. --- CHANGES.txt | 23 +++++++++ MANIFEST.in | 1 + fnpdjango/management/__init__.py | 0 fnpdjango/management/commands/__init__.py | 0 fnpdjango/management/commands/babel.cfg | 5 ++ .../commands/makecontribmessages.py | 50 +++++++++++++++++++ setup.py | 1 + 7 files changed, 80 insertions(+) create mode 100644 CHANGES.txt create mode 100755 fnpdjango/management/__init__.py create mode 100755 fnpdjango/management/commands/__init__.py create mode 100755 fnpdjango/management/commands/babel.cfg create mode 100755 fnpdjango/management/commands/makecontribmessages.py diff --git a/CHANGES.txt b/CHANGES.txt new file mode 100644 index 0000000..71a81a1 --- /dev/null +++ b/CHANGES.txt @@ -0,0 +1,23 @@ + - Add a management command for localizing contrib apps. + - Fix deployment sudo problem. + +v0.1.4 2013-01-10 + - Add tQ function for filtering translated fields. + +v0.1.3 2013-01-09 + - Fix get_here_url. + - Nicer project starter. + - Fix deployment scripts. + +v0.1.2 2012-11-30 + - Added app settings. + - Fix deployment scripts. + - Minor fixes. + +v0.1.1 2012-11-22 + - Deployment scripts. + - Minor fixes. + +v0.1 2012-11-05 + - Initial release. + diff --git a/MANIFEST.in b/MANIFEST.in index 27f7cdf..9c1b30c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ +include *.txt recursive-include fnpdjango/templates *.html recursive-include fnpdjango/locale *.po *.mo recursive-include fnpdjango/deploy/templates *.template diff --git a/fnpdjango/management/__init__.py b/fnpdjango/management/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/fnpdjango/management/commands/__init__.py b/fnpdjango/management/commands/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/fnpdjango/management/commands/babel.cfg b/fnpdjango/management/commands/babel.cfg new file mode 100755 index 0000000..57dc23e --- /dev/null +++ b/fnpdjango/management/commands/babel.cfg @@ -0,0 +1,5 @@ +[extractors] +django = babeldjango.extract:extract_django + +[django: templates/**.*] +[python: **.py] diff --git a/fnpdjango/management/commands/makecontribmessages.py b/fnpdjango/management/commands/makecontribmessages.py new file mode 100755 index 0000000..5aa8fa1 --- /dev/null +++ b/fnpdjango/management/commands/makecontribmessages.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +import os +from optparse import make_option +from django.core.management.base import BaseCommand + +class Command(BaseCommand): + help = 'Builds .po files for contrib apps.' + + def handle(self, **options): + from django.conf import settings + + if not hasattr(settings, 'CONTRIB_LOCALE_APPS') or not settings.CONTRIB_LOCALE_APPS: + print "CONTRIB_LOCALE_APPS not set, no contrib locale needed." + return + + from subprocess import call + import babel + + app_names = settings.CONTRIB_LOCALE_APPS + print 'L10n for:', ", ".join(app_names) + app_dirs = [os.path.dirname(__import__(app).__file__) + for app in app_names] + assert settings.LOCALE_PATHS + locale_path = settings.LOCALE_PATHS[0] + print 'Using:', locale_path + + # Create the POT file. + babel_cfg = os.path.join(locale_path, "babel.cfg") + if not os.path.exists(babel_cfg): + babel_cfg = os.path.join(os.path.dirname(__file__), 'babel.cfg') + pot_path = os.path.join(locale_path, "django.pot") + call(["pybabel", "extract", + "-F", babel_cfg, + "-o", pot_path] + app_dirs) + + # Lose the unneeded absolute file paths in the POT. + with open(pot_path) as f: + pot = f.read() + for i, app_dir in enumerate(app_dirs): + pot = pot.replace("\n#: " + app_dir, "\n#: " + app_names[i]) + with open(pot_path, 'w') as f: + f.write(pot) + + # Create/update the PO files. + call(["pybabel", "update", "-D", "django", + "-i", pot_path, + "-d", locale_path]) diff --git a/setup.py b/setup.py index 87a5a5e..b00ffd4 100755 --- a/setup.py +++ b/setup.py @@ -30,6 +30,7 @@ setup( package_data={ 'fnpdjango': whole_trees('fnpdjango', ['templates', 'locale']), 'fnpdjango.deploy': ['templates/*.template'], + 'fnpdjango.management.commands': ['babel.cfg'], }, scripts=[ 'bin/git-archive-all.sh', -- 2.20.1