Browse Source

#488: Call misago makemessages from misago-admin

Rafał Pitoń 10 years ago
parent
commit
d870318d23
3 changed files with 67 additions and 1 deletions
  1. 22 0
      misago/bin/misago-admin.py
  2. 41 0
      misago/core/management/commands/makemessages.py
  3. 4 1
      setup.py

+ 22 - 0
misago/bin/misago-admin.py

@@ -0,0 +1,22 @@
+"""
+Misago wrapper for Django admin
+
+This wrapper users Misago makemessages instead of Django one, making it work
+for Handlebars templates in addition to .js files.
+"""
+from django.core.management import ManagementUtility
+
+from misago.core.management.commands.makemessages import Command
+
+
+class MisagoAdmin(ManagementUtility):
+    def fetch_command(self, subcommand):
+        if subcommand == "makemessages":
+            return Command()
+        else:
+            return super(MisagoAdmin, self).fetch_command(subcommand)
+
+
+if __name__ == '__main__':
+    utility = MisagoAdmin()
+    utility.execute()

+ 41 - 0
misago/core/management/commands/makemessages.py

@@ -0,0 +1,41 @@
+from django.core.management.commands.makemessages import Command as BaseCommand
+
+
+class Command(BaseCommand):
+    help = ("Runs over the entire source tree of the current directory and "
+"pulls out all strings marked for translation. It creates (or updates) a message "
+"file in the conf/locale (in the django tree) or locale (for projects and "
+"applications) directory.\n\nIf command is executed for JavaScript files, it "
+"also pulls strings from Misago Handlebars.js files.\n\nYou must run this "
+"command with one of either the --locale, --exclude or --all options.")
+
+    JS_TEMPLATES = ('.hbs', '.handlebars')
+
+    def handle(self, *args, **options):
+        locale = options.get('locale')
+        exclude = options.get('exclude')
+        self.domain = options.get('domain')
+        self.verbosity = options.get('verbosity')
+        process_all = options.get('all')
+        extensions = options.get('extensions')
+        self.symlinks = options.get('symlinks')
+
+        if self.domain == 'djangojs':
+            # fake js files from templates
+            self.prepare_tmp_js_templates();
+
+        super(Command, self).handle(*args, **options)
+
+        if self.domain == 'djangojs':
+            # cleanup everything
+            self.cleanup_po_files();
+            self.cleanup_tmp_js_templates();
+
+    def prepare_tmp_js_templates(self):
+        pass
+
+    def cleanup_po_files(self):
+        pass
+
+    def cleanup_tmp_js_templates(self):
+        pass

+ 4 - 1
setup.py

@@ -36,7 +36,10 @@ setup(
     ],
     packages=find_packages(exclude=EXCLUDE_FROM_PACKAGES),
     include_package_data=True,
-    scripts=['misago/bin/misago-start.py'],
+    scripts=[
+        'misago/bin/misago-start.py',
+        'misago/bin/misago-makemessages.py',
+    ],
     entry_points={'console_scripts': [
         'misago-start = misago.core.setup:start_misago_project',
     ]},