Пример #1
0
 def get_command(cls, app_name, domain):
     assert domain in ('django', 'djangojs')
     check_programs('xgettext', 'msguniq', 'msgmerge', 'msgattrib')
     co = cls()
     co.domain = domain
     co.extensions = handle_extensions(GETTEXT_EXTENSIONS[domain])
     co._update_locale_paths(app_name)
     return co
Пример #2
0
 def compilemessages(cls):
     check_programs('msgfmt')
     basedirs = [os.path.join(app, 'locale').replace('\\', '/') for app in APPS]
     co = cls()
     for basedir in basedirs:
         dirs = [os.path.join(basedir, locale, 'LC_MESSAGES').replace('\\', '/') for locale in LANGUAGES]
         locations = []
         for ldir in dirs:
             for dirpath, dirnames, filenames in os.walk(ldir):
                 locations.extend((dirpath, f) for f in filenames if f.endswith('.po'))
         if locations:
             co.compile_messages(locations)
Пример #3
0
def makemessages(*args):
    from django.conf import settings
    settings.configure()
    settings.MEDIA_ROOT = settings.STATIC_ROOT = '/-nopath-'
    check_programs('xgettext', 'msguniq', 'msgmerge', 'msgattrib')
    for app_name in APPS:
        for domain in ('django', 'djangojs'):
            co = MakemessagesCommand.get_command(app_name, domain)
            co.stdout.write("app: %s, domain: %s\n" % (app_name, domain))
            try:
                potfiles = co.build_potfiles()
                for locale in LANGUAGES:
                    if co.verbosity > 0:
                        co.stdout.write('processing locale %s\n' % locale)
                    for potfile in potfiles:
                        co.write_po_file(potfile, locale)
            finally:
                if not co.keep_pot:
                    co.remove_potfiles()
Пример #4
0
    def handle(self, *args, **options):
        locale = options.get('locale')
        exclude = options.get('exclude')
        self.domain = 'dmoj-user'
        self.verbosity = options.get('verbosity')
        process_all = options.get('all')

        # Need to ensure that the i18n framework is enabled
        if settings.configured:
            settings.USE_I18N = True
        else:
            settings.configure(USE_I18N=True)

        # Avoid messing with mutable class variables
        if options.get('no_wrap'):
            self.msgmerge_options = self.msgmerge_options[:] + ['--no-wrap']
            self.msguniq_options = self.msguniq_options[:] + ['--no-wrap']
            self.msgattrib_options = self.msgattrib_options[:] + ['--no-wrap']
            self.xgettext_options = self.xgettext_options[:] + ['--no-wrap']
        if options.get('no_location'):
            self.msgmerge_options = self.msgmerge_options[:] + ['--no-location']
            self.msguniq_options = self.msguniq_options[:] + ['--no-location']
            self.msgattrib_options = self.msgattrib_options[:] + ['--no-location']
            self.xgettext_options = self.xgettext_options[:] + ['--no-location']

        self.no_obsolete = options.get('no_obsolete')
        self.keep_pot = options.get('keep_pot')

        if locale is None and not exclude and not process_all:
            raise CommandError("Type '%s help %s' for usage information." % (
                os.path.basename(sys.argv[0]), sys.argv[1]))

        self.invoked_for_django = False
        self.locale_paths = []
        self.default_locale_path = None
        if os.path.isdir(os.path.join('conf', 'locale')):
            self.locale_paths = [os.path.abspath(os.path.join('conf', 'locale'))]
            self.default_locale_path = self.locale_paths[0]
            self.invoked_for_django = True
        else:
            self.locale_paths.extend(settings.LOCALE_PATHS)
            # Allow to run makemessages inside an app dir
            if os.path.isdir('locale'):
                self.locale_paths.append(os.path.abspath('locale'))
            if self.locale_paths:
                self.default_locale_path = self.locale_paths[0]
                if not os.path.exists(self.default_locale_path):
                    os.makedirs(self.default_locale_path)

        # Build locale list
        locale_dirs = list(filter(os.path.isdir, glob.glob('%s/*' % self.default_locale_path)))
        all_locales = list(map(os.path.basename, locale_dirs))

        # Account for excluded locales
        if process_all:
            locales = all_locales
        else:
            locales = locale or all_locales
            locales = set(locales) - set(exclude)

        if locales:
            check_programs('msguniq', 'msgmerge', 'msgattrib')

        check_programs('xgettext')

        try:
            potfiles = self.build_potfiles()

            # Build po files for each selected locale
            for locale in locales:
                if self.verbosity > 0:
                    self.stdout.write("processing locale %s\n" % locale)
                for potfile in potfiles:
                    self.write_po_file(potfile, locale)
        finally:
            if not self.keep_pot:
                self.remove_potfiles()