Last active
January 11, 2019 00:22
-
-
Save vonNiklasson/5fec59ad635ff3083f914188cb6736cf to your computer and use it in GitHub Desktop.
Management script for Django to easily run the 'makemessages'-command for all files in your Django application.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
translate.py | |
Management script for Django to easily run the | |
'makemessages'-command for all files in your Django application. | |
Put in any registered django app in the location | |
<app>/management/commands/translate.py | |
and then use | |
python manage.py translate | |
to run makemessages on all files in your project | |
TODO: Move ignore-configuration to django.conf.settings-file instead | |
Made by Johan Niklasson | |
https://github.com/vonNiklasson | |
https://gist.github.com/vonNiklasson/5fec59ad635ff3083f914188cb6736cf | |
''' | |
from django.core.management.base import BaseCommand | |
from django.core import management | |
from django.conf import settings | |
class Command(BaseCommand): | |
help = "Runs command makemessages for all domains" | |
def add_arguments(self, parser): | |
parser.add_argument('--regular', | |
action='store_true', | |
dest='regular', | |
default=False, | |
help='Makes the translation for python and template files only (excludes JavaScript translation unless stated)') | |
parser.add_argument('--js', | |
action='store_true', | |
dest='js', | |
default=False, | |
help='Makes the translation for javascript files only (excludes regular translation unless stated)') | |
def handle(self, *args, **options): | |
languages = [ seq[0] for seq in settings.LANGUAGES ]; | |
if options['regular'] == True or (options['regular'] == False and options['js'] == False): | |
self.stdout.write("Translating Python and template files") | |
management.call_command('makemessages', locale=languages, domain='django', ignore=['node_modules/*']) | |
if options['js'] == True or (options['js'] == False and options['regular'] == False): | |
self.stdout.write("Translating JavaScript files") | |
management.call_command('makemessages', locale=languages, domain='djangojs', ignore=['node_modules/*']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment