Add management command for localizing contrib apps.
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 22 Feb 2013 10:54:22 +0000 (11:54 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 22 Feb 2013 10:54:22 +0000 (11:54 +0100)
CHANGES.txt [new file with mode: 0644]
MANIFEST.in
fnpdjango/management/__init__.py [new file with mode: 0755]
fnpdjango/management/commands/__init__.py [new file with mode: 0755]
fnpdjango/management/commands/babel.cfg [new file with mode: 0755]
fnpdjango/management/commands/makecontribmessages.py [new file with mode: 0755]
setup.py

diff --git a/CHANGES.txt b/CHANGES.txt
new file mode 100644 (file)
index 0000000..71a81a1
--- /dev/null
@@ -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.
+
index 27f7cdf..9c1b30c 100644 (file)
@@ -1,3 +1,4 @@
+include *.txt
 recursive-include fnpdjango/templates *.html
 recursive-include fnpdjango/locale *.po *.mo
 recursive-include fnpdjango/deploy/templates *.template
 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 (executable)
index 0000000..e69de29
diff --git a/fnpdjango/management/commands/__init__.py b/fnpdjango/management/commands/__init__.py
new file mode 100755 (executable)
index 0000000..e69de29
diff --git a/fnpdjango/management/commands/babel.cfg b/fnpdjango/management/commands/babel.cfg
new file mode 100755 (executable)
index 0000000..57dc23e
--- /dev/null
@@ -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 (executable)
index 0000000..5aa8fa1
--- /dev/null
@@ -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])
index 87a5a5e..b00ffd4 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -30,6 +30,7 @@ setup(
     package_data={
         'fnpdjango': whole_trees('fnpdjango', ['templates', 'locale']),
         'fnpdjango.deploy': ['templates/*.template'],
     package_data={
         'fnpdjango': whole_trees('fnpdjango', ['templates', 'locale']),
         'fnpdjango.deploy': ['templates/*.template'],
+        'fnpdjango.management.commands': ['babel.cfg'],
     },
     scripts=[
         'bin/git-archive-all.sh',
     },
     scripts=[
         'bin/git-archive-all.sh',