Пример #1
0
    def handle(self, args):
        from django.core.management.commands.makemessages import make_messages, handle_extensions
        from django.db import models
        from djangojs.conf import settings

        if not args.apps:
            raise CommandError('Enter at least one application name.')

        if not (args.locale or args.all):
            raise CommandError('Enter a locale or use the --all switch.')

        ignore_patterns = args.ignore
        if args.no_default_ignore:
            ignore_patterns += ['CVS', '.*', '*~']
        ignore_patterns = list(set(ignore_patterns))

        extensions = handle_extensions(args.extensions)

        try:
            apps = [models.get_app(app) for app in args.apps]
        except (ImproperlyConfigured, ImportError) as e:
            raise CommandError("%s. Are you sure your INSTALLED_APPS setting is correct?" % e)

        for app in apps:
            app_dir = os.path.dirname(app.__file__)
            os.chdir(app_dir)

            catalogs = [self.build_catalog(root, ext, regexp) for ext, root, regexp in settings.JS_I18N_PATTERNS]

            make_messages(args.locale, b'djangojs', args.verbosity, args.all, extensions,
                          args.symlinks, ignore_patterns, args.no_wrap, args.no_location,
                          args.no_obsolete, self.stdout)

            for catalog in catalogs:
                os.remove(catalog)
Пример #2
0
    def handle(self, *args, **options):
        from thepian.conf import import_structure

        structure = import_structure(os.getcwd())
        try:
            import django
        except ImportError:
            if structure.DEVELOPING:
                site.addsitedir(structure.LIB_DIR)
        import django
        from django.core.management.commands.makemessages import make_messages, handle_extensions

        if len(args) != 0:
            raise CommandError("Command doesn't accept any arguments")

        locale = options.get("locale")
        domain = options.get("domain")
        verbosity = int(options.get("verbosity"))
        process_all = options.get("all")
        extensions = options.get("extensions") or ["html"]

        if domain == "djangojs":
            extensions = []
        else:
            extensions = handle_extensions(extensions)

        if ".js" in extensions:
            raise CommandError("JavaScript files should be examined by using the special 'djangojs' domain only.")

        # old_cwd = os.getcwd()
        # os.chdir(os.path.dirname(django.__file__))
        make_messages(locale, domain, verbosity, process_all, extensions)
Пример #3
0
    def makemessages(self):
        saved = os.getcwd()
        os.chdir(LocalePath.get_app_path(self.app))
#        print os.getcwd()
        make_messages(locale = cur_lang(), domain='django', verbosity =0, extensions=['.html', '.eml'])
#    make_messages(locale, domain, verbosity, process_all, extensions)
        os.chdir(saved)
Пример #4
0
    def handle(self, *args, **options):
        if len(args) != 0:
            raise CommandError("Command doesn't accept any arguments")

        locale = options.get('locale')
        domain = options.get('domain')
        verbosity = int(options.get('verbosity'))
        process_all = options.get('all')
        extensions = options.get('extensions') or ['html']

        if domain == 'djangojs':
            extensions = []
        else:
            extensions = handle_extensions(extensions)

        if '.js' in extensions:
            raise CommandError("JavaScript files should be examined by using the special 'djangojs' domain only.")

        # The hacking part is here
        if process_all:
            if os.path.isdir(os.path.join('conf', 'locale')):
                localedir = os.path.abspath(os.path.join('conf', 'locale'))
            elif os.path.isdir('locale'):
                localedir = os.path.abspath('locale')
            else:
                raise CommandError("This script should be run from the Transifex project tree.")

            # Only for directories under the locale dir, make_messages
            locale_dirs = filter(os.path.isdir, glob.glob('%s/*' % localedir))
            for locale_dir in locale_dirs:
                locale = os.path.basename(locale_dir)
                make_messages(locale, domain, verbosity, False, extensions)
        else:
            make_messages(locale, domain, verbosity, process_all, extensions)
Пример #5
0
 def makemessages(self):
     saved = os.getcwd()
     os.chdir(LocalePath.get_app_path(self.app))
     #        print os.getcwd()
     make_messages(locale=cur_lang(),
                   domain='django',
                   verbosity=0,
                   extensions=['.html', '.eml'])
     #    make_messages(locale, domain, verbosity, process_all, extensions)
     os.chdir(saved)
    def handle(self, locale=None, **kwargs):
        extensions=['*.py', '*.html']

        if not locale:
            print "Generating translation files for all available locales."
            makemessages.make_messages(all=True, verbosity=2, extensions=extensions)
            compilemessages.compile_messages()
        else:
            try:
                print "Generating translation files for %s" % locale
                makemessages.make_messages(locale=locale, all=False, verbosity=2, extensions=extensions)
                compilemessages.compile_messages(locale=locale)
            except Exception, e:
                print "There was an error generating translation files for %s" % locale
    def handle(self, *args, **options):
        if len(args) != 0:
            raise CommandError("Command doesn't accept any arguments")

        locale = options.get('locale')
        domain = options.get('domain')
        verbosity = int(options.get('verbosity'))
        process_all = options.get('all')
        extensions = options.get('extensions') or ['html']

        if domain == 'djangojs':
            extensions = []
        else:
            extensions = handle_extensions(extensions)

        if '.js' in extensions:
            raise CommandError(
                "JavaScript files should be examined by using the special 'djangojs' domain only."
            )

        # The hacking part is here
        if process_all:
            if os.path.isdir(os.path.join('conf', 'locale')):
                localedir = os.path.abspath(os.path.join('conf', 'locale'))
            elif os.path.isdir('locale'):
                localedir = os.path.abspath('locale')
            else:
                raise CommandError(
                    "This script should be run from the Transifex project tree."
                )

            # Only for directories under the locale dir, make_messages
            locale_dirs = filter(os.path.isdir, glob.glob('%s/*' % localedir))
            for locale_dir in locale_dirs:
                locale = os.path.basename(locale_dir)
                make_messages(locale, domain, verbosity, False, extensions)
        else:
            make_messages(locale, domain, verbosity, process_all, extensions)
Пример #8
0
    def get_context_data(self, **kwargs):
        context = super(GenerateTranslationMessagesView, self).get_context_data(**kwargs)
        
        if hasattr(self, 'error') and self.error:
            context['error'] = self.error
            return context
        
        #locate the current directory
        curr_dir = os.curdir
        domain_dict = {'django' : ['html','txt'], 'djangojs' : ['js']}
        
        lang_files = []
        #iterate over the installed applications and copy their po files
        #for this language to the appropriate folder 
        for app_name in settings.INSTALLED_APPS:    
            
            mod = import_module(app_name)
            mod_root = os.path.dirname(mod.__file__)

            if not os.path.exists(os.path.join(mod_root, 'locale')):
                continue
            
            original_path = os.path.join(mod_root, 'locale', to_locale(self.language.name), 'LC_MESSAGES')
            delete_at_the_end = False
            
            if not os.path.exists(original_path):
                if not app_name.startswith('django.contrib'):
                    try: #try to create language directory for the app
                        os.makedirs(original_path)
                        delete_at_the_end = True
                    except:
                        continue
                else:
                    continue
            
            if not app_name.startswith('django.contrib'):
                #move original files to a temp file
                for file_ in list(os.listdir(original_path)):
                        if file_.endswith('.po'):
                            shutil.copy(os.path.join(original_path, file_), os.path.join(original_path, 'original-%s' % file_))
                
                #copy the project-wise files to the appropriate directory
                if not self.request.GET.get('delete', 0):
                    #replace original file with the yawd version
                    #so that it gets updated
                    for f in list(os.listdir(self.po_path)):
                        if f.startswith('%s-' % app_name) and f.endswith('.po'):
                            shutil.copy(os.path.join(self.po_path, f), os.path.join(original_path, f.replace('%s-' % app_name, '')))  

                #makemessages excluding the core applications
                os.chdir(mod_root)
                for key, value in domain_dict.items():
                    make_messages(locale=self.locale, domain=key, extensions=handle_extensions(value), verbosity=0)
                os.chdir(curr_dir)

            #iterate over the application po files
            for file_ in list(os.listdir(original_path)):
                if not file_.startswith('original-') and file_.endswith('.po'):
                    original_file_path = os.path.join(original_path, file_)
                    file_name = '%s-%s' % (app_name, file_)
                    
                    #copy file
                    copy_path = os.path.join(self.po_path, file_name)
                    if self.request.GET.get('delete', 0) or not (app_name.startswith('django.contrib') and os.path.exists(copy_path)):
                        shutil.copy(original_file_path, copy_path)
                        os.chmod(copy_path, 0664)
                    
                    #unlink updated file
                    if not app_name.startswith('django.contrib'):
                        os.unlink(original_file_path)
                    
                    lang_files.append(file_name)
            
            if not app_name.startswith('django.contrib'):
                if delete_at_the_end:
                    shutil.rmtree(os.path.join(mod_root, 'locale', to_locale(self.language.name)))
                else:
                    for file_ in os.listdir(original_path):
                        #put back the original application files
                        if file_.startswith('original-') and file_.endswith('.po'):
                            shutil.move(os.path.join(original_path, file_), os.path.join(original_path, file_.replace('original-','')))
                
        #concat all messages in a single .po file for each domain
        for domain in domain_dict:
            file_name = '%s.po' % domain
            uni_django_path = os.path.join(self.po_path, file_name)

            if os.path.exists(uni_django_path):
                os.unlink(uni_django_path)

            source_files = [os.path.join(self.po_path, f) for f in lang_files if f.endswith(file_name)]
            if source_files:
                #merge .po files
                concat_message_files(source_files, uni_django_path)
                #compile django.po
                if not has_bom(uni_django_path):
                    compile_message_file(uni_django_path)

        #reset the cached translation messages so that
        #we do not need to restart the web server
        reset_translations(self.language.name)
        
        context['lang_files'] = sorted(lang_files)
        return context
Пример #9
0
    def handle(self, *args, **options):
        self.verbosity = int(options.get('verbosity'))
        locale = options.get('locale')
        if locale is None:
            process_all = True
        else:
            process_all = False

        if len(args) == 0:
            raise CommandError("missing '%s' or '%s' argument!" % (MAKE_MESSAGES, COMPILE_MESSAGES))

        cmd_type = args[0]
        if cmd_type not in (MAKE_MESSAGES, COMPILE_MESSAGES):
            raise CommandError("First argument must be '%s' or '%s' !" % (MAKE_MESSAGES, COMPILE_MESSAGES))

        pylucid_app_names = self._pylucid_app_names()

        if len(args) > 1:
            only_apps = args[1:]
            sys.stdout.write("%s only the apps: %s" % (cmd_type, repr(only_apps)))

            app_names = []
            for app_name in only_apps:
                if app_name in pylucid_app_names:
                    app_names.append(app_name)
                else:
                    app_name = ".%s" % app_name
                    full_app_name = None
                    for app_name2 in pylucid_app_names:
                        if app_name2.endswith(app_name):
                            full_app_name = app_name2
                            break
                    if full_app_name is None:
                        sys.stderr.write("App with name %r is unknown or not a PyLucid app!" % app_name)
                    else:
                        app_names.append(full_app_name)
            if not app_names:
                raise CommandError("No valid PyLucid apps found!")
        else:
            app_names = pylucid_app_names

        for app_name in app_names:
            print "_"*79
            print "%s: %s" % (cmd_type, app_name)
            app_module = import_module(app_name)
            app_path = os.path.dirname(app_module.__file__)

            os.chdir(app_path)

            if cmd_type == COMPILE_MESSAGES:
                try:
                    compile_messages(self.stderr)
                except Exception:
                    print traceback.format_exc()
            elif cmd_type == MAKE_MESSAGES:
                try:
                    make_messages(
                        locale=locale,
                        domain="django",
                        verbosity=self.verbosity,
                        all=process_all,
                        extensions=[".html", ],
                        symlinks=True,
                        ignore_patterns=['CVS', '.*', '*~'],
                        no_wrap=False,
                        no_obsolete=True,
                    )
                except Exception:
                    print traceback.format_exc()
            else:
                raise