def main(): logging.basicConfig(stream=sys.stdout, level=logging.INFO) create_dir_if_necessary(LOCALE_DIR) source_msgs_dir = CONFIGURATION.source_messages_dir remove_file(source_msgs_dir.joinpath('django.po')) # Extract strings from mako templates. babel_mako_cmd = 'pybabel extract -F %s -c "Translators:" . -o %s' % (BABEL_CONFIG, BABEL_OUT) execute(babel_mako_cmd, working_directory=BASE_DIR) makemessages = "django-admin.py makemessages -l en" ignores = " ".join('--ignore="{}/*"'.format(d) for d in CONFIGURATION.ignore_dirs) if ignores: makemessages += " " + ignores # Extract strings from django source files, including .py files. make_django_cmd = makemessages + ' --extension html' execute(make_django_cmd, working_directory=BASE_DIR) # Extract strings from Javascript source files. make_djangojs_cmd = makemessages + ' -d djangojs --extension js' execute(make_djangojs_cmd, working_directory=BASE_DIR) # makemessages creates 'django.po'. This filename is hardcoded. # Rename it to django-partial.po to enable merging into django.po later. os.rename( source_msgs_dir.joinpath('django.po'), source_msgs_dir.joinpath('django-partial.po') ) # makemessages creates 'djangojs.po'. This filename is hardcoded. # Rename it to djangojs-partial.po to enable merging into djangojs.po later. os.rename( source_msgs_dir.joinpath('djangojs.po'), source_msgs_dir.joinpath('djangojs-partial.po') ) # Segment the generated files. segmented_files = segment_pofiles("en") # Finish each file. for filename in segmented_files: LOG.info('Cleaning %s' % filename) po = pofile(source_msgs_dir.joinpath(filename)) # replace default headers with edX headers fix_header(po) # replace default metadata with edX metadata fix_metadata(po) # remove key strings which belong in messages.po strip_key_strings(po) po.save()
def main(): logging.basicConfig(stream=sys.stdout, level=logging.INFO) create_dir_if_necessary(LOCALE_DIR) source_msgs_dir = CONFIGURATION.source_messages_dir remove_file(source_msgs_dir.joinpath('django.po')) makemessages = "django-admin.py makemessages -l en" ignores = " ".join('--ignore="{}/*"'.format(d) for d in CONFIGURATION.ignore_dirs) if ignores: makemessages += " " + ignores # Extract strings from mako templates. babel_mako_cmd = 'pybabel extract -F %s -c "Translators:" . -o %s' % ( BABEL_CONFIG, BABEL_OUT) execute(babel_mako_cmd, working_directory=BASE_DIR) # Extract strings from django source files, including .py files. make_django_cmd = makemessages + ' --extension html' execute(make_django_cmd, working_directory=BASE_DIR) # Extract strings from Javascript source files. make_djangojs_cmd = makemessages + ' -d djangojs --extension js' execute(make_djangojs_cmd, working_directory=BASE_DIR) # makemessages creates 'django.po'. This filename is hardcoded. # Rename it to django-partial.po to enable merging into django.po later. os.rename(source_msgs_dir.joinpath('django.po'), source_msgs_dir.joinpath('django-partial.po')) # Segment the generated files. segmented_files = segment_pofiles("en") # Finish each file. for filename in segmented_files: LOG.info('Cleaning %s' % filename) po = pofile(source_msgs_dir.joinpath(filename)) # replace default headers with edX headers fix_header(po) # replace default metadata with edX metadata fix_metadata(po) # remove key strings which belong in messages.po strip_key_strings(po) po.save()
def main(): logging.basicConfig(stream=sys.stdout, level=logging.INFO) create_dir_if_necessary(LOCALE_DIR) source_msgs_dir = CONFIGURATION.source_messages_dir remove_file(source_msgs_dir.joinpath("django.po")) generated_files = ("django-partial.po", "djangojs.po", "mako.po") for filename in generated_files: remove_file(source_msgs_dir.joinpath(filename)) # Prepare makemessages command. ignore_dirs = ["docs", "src", "i18n", "test_root"] ignores = " ".join("--ignore={}/*".format(d) for d in ignore_dirs) makemessages = "django-admin.py makemessages -l en " + ignores # Extract strings from mako templates. babel_mako_cmd = 'pybabel extract -F %s -c "Translators:" . -o %s' % (BABEL_CONFIG, BABEL_OUT) execute(babel_mako_cmd, working_directory=BASE_DIR) # Extract strings from django source files, including .py files. make_django_cmd = makemessages + " --extension html" execute(make_django_cmd, working_directory=BASE_DIR) # Extract strings from Javascript source files. make_djangojs_cmd = makemessages + " -d djangojs --extension js" execute(make_djangojs_cmd, working_directory=BASE_DIR) # makemessages creates 'django.po'. This filename is hardcoded. # Rename it to django-partial.po to enable merging into django.po later. os.rename(source_msgs_dir.joinpath("django.po"), source_msgs_dir.joinpath("django-partial.po")) for filename in generated_files: LOG.info("Cleaning %s" % filename) po = pofile(source_msgs_dir.joinpath(filename)) # replace default headers with edX headers fix_header(po) # replace default metadata with edX metadata fix_metadata(po) # remove key strings which belong in messages.po strip_key_strings(po) po.save()
def main(): logging.basicConfig(stream=sys.stdout, level=logging.INFO) create_dir_if_necessary(LOCALE_DIR) source_msgs_dir = CONFIGURATION.source_messages_dir remove_file(source_msgs_dir.joinpath('django.po')) # Extract strings from mako templates. babel_mako_cmd = 'pybabel extract -k ugettext_lazy -k _u -F {config} -c "Translators:" . -o {output}' babel_mako_cmd = babel_mako_cmd.format( config=base(LOCALE_DIR, 'babel_mako.cfg'), output=base(CONFIGURATION.source_messages_dir, 'mako.po'), ) execute(babel_mako_cmd, working_directory=BASE_DIR) makemessages = "django-admin.py makemessages -l en" ignores = " ".join('--ignore="{}/*"'.format(d) for d in CONFIGURATION.ignore_dirs) if ignores: makemessages += " " + ignores # Extract strings from django source files, including .py files. make_django_cmd = makemessages + ' --extension html' execute(make_django_cmd, working_directory=BASE_DIR) # Extract strings from Javascript source files. make_djangojs_cmd = makemessages + ' -d djangojs --extension js' execute(make_djangojs_cmd, working_directory=BASE_DIR) # makemessages creates 'django.po'. This filename is hardcoded. # Rename it to django-partial.po to enable merging into django.po later. os.rename( source_msgs_dir.joinpath('django.po'), source_msgs_dir.joinpath('django-partial.po') ) # makemessages creates 'djangojs.po'. This filename is hardcoded. # Rename it to djangojs-partial.po to enable merging into djangojs.po later. os.rename( source_msgs_dir.joinpath('djangojs.po'), source_msgs_dir.joinpath('djangojs-partial.po') ) files_to_clean = set() # Extract strings from third-party applications. for app_name in CONFIGURATION.third_party: # Import the app to find out where it is. Then use pybabel to extract # from that directory. app_module = importlib.import_module(app_name) app_dir = path(app_module.__file__).dirname().dirname() output_file = source_msgs_dir / (app_name + ".po") files_to_clean.add(output_file) babel_cmd = 'pybabel extract -F {config} -c "Translators:" {app} -o {output}' babel_cmd = babel_cmd.format( config=LOCALE_DIR / 'babel_third_party.cfg', app=app_name, output=output_file, ) execute(babel_cmd, working_directory=app_dir) # Segment the generated files. segmented_files = segment_pofiles("en") files_to_clean.update(segmented_files) # Finish each file. for filename in files_to_clean: LOG.info('Cleaning %s' % filename) po = pofile(source_msgs_dir.joinpath(filename)) # replace default headers with edX headers fix_header(po) # replace default metadata with edX metadata fix_metadata(po) # remove key strings which belong in messages.po strip_key_strings(po) po.save()
def main(verbosity=1): """ Main entry point of script """ logging.basicConfig(stream=sys.stdout, level=logging.INFO) LOCALE_DIR.parent.makedirs_p() source_msgs_dir = CONFIGURATION.source_messages_dir remove_file(source_msgs_dir.joinpath('django.po')) # Extract strings from mako templates. verbosity_map = { 0: "-q", 1: "", 2: "-v", } babel_verbosity = verbosity_map.get(verbosity, "") babel_mako_cmd = 'pybabel {verbosity} extract -F {config} -c "Translators:" . -o {output}' babel_mako_cmd = babel_mako_cmd.format( verbosity=babel_verbosity, config=base(LOCALE_DIR, 'babel_mako.cfg'), output=base(CONFIGURATION.source_messages_dir, 'mako.po'), ) if verbosity: stderr = None else: stderr = DEVNULL execute(babel_mako_cmd, working_directory=BASE_DIR, stderr=stderr) makemessages = "django-admin.py makemessages -l en -v{}".format(verbosity) ignores = " ".join('--ignore="{}/*"'.format(d) for d in CONFIGURATION.ignore_dirs) if ignores: makemessages += " " + ignores # Extract strings from django source files, including .py files. make_django_cmd = makemessages + ' --extension html' execute(make_django_cmd, working_directory=BASE_DIR, stderr=stderr) # Extract strings from Javascript source files. make_djangojs_cmd = makemessages + ' -d djangojs --extension js' execute(make_djangojs_cmd, working_directory=BASE_DIR, stderr=stderr) # Extract and megre strings from underscore files extract_and_merge_underscore() # makemessages creates 'django.po'. This filename is hardcoded. # Rename it to django-partial.po to enable merging into django.po later. os.rename( source_msgs_dir.joinpath('django.po'), source_msgs_dir.joinpath('django-partial.po') ) # makemessages creates 'djangojs.po'. This filename is hardcoded. # Rename it to djangojs-partial.po to enable merging into djangojs.po later. os.rename( source_msgs_dir.joinpath('djangojs.po'), source_msgs_dir.joinpath('djangojs-partial.po') ) files_to_clean = set() # Extract strings from third-party applications. for app_name in CONFIGURATION.third_party: # Import the app to find out where it is. Then use pybabel to extract # from that directory. app_module = importlib.import_module(app_name) app_dir = path(app_module.__file__).dirname().dirname() output_file = source_msgs_dir / (app_name + ".po") files_to_clean.add(output_file) babel_cmd = 'pybabel {verbosity} extract -F {config} -c "Translators:" {app} -o {output}' babel_cmd = babel_cmd.format( verbosity=babel_verbosity, config=LOCALE_DIR / 'babel_third_party.cfg', app=app_name, output=output_file, ) execute(babel_cmd, working_directory=app_dir, stderr=stderr) # Segment the generated files. segmented_files = segment_pofiles("en") files_to_clean.update(segmented_files) # Finish each file. for filename in files_to_clean: LOG.info('Cleaning %s' % filename) po = pofile(source_msgs_dir.joinpath(filename)) # replace default headers with edX headers fix_header(po) # replace default metadata with edX metadata fix_metadata(po) # remove key strings which belong in messages.po strip_key_strings(po) po.save()
def run(self, args): """ Main entry point of script """ logging.basicConfig(stream=sys.stdout, level=logging.INFO) config.LOCALE_DIR.parent.makedirs_p() source_msgs_dir = config.CONFIGURATION.source_messages_dir remove_file(source_msgs_dir.joinpath('django.po')) # Extract strings from mako templates. verbosity_map = { 0: "-q", 1: "", 2: "-v", } babel_verbosity = verbosity_map.get(args.verbose, "") babel_mako_cfg = base(config.LOCALE_DIR, 'babel_mako.cfg') if args.verbose: stderr = None else: stderr = DEVNULL if babel_mako_cfg.exists(): babel_mako_cmd = 'pybabel {verbosity} extract -F {config} -c "Translators:" . -o {output}' babel_mako_cmd = babel_mako_cmd.format( verbosity=babel_verbosity, config=babel_mako_cfg, output=base(config.CONFIGURATION.source_messages_dir, 'mako.po'), ) execute(babel_mako_cmd, working_directory=config.BASE_DIR, stderr=stderr) makemessages = "django-admin.py makemessages -l en -v{}".format(args.verbose) ignores = " ".join('--ignore="{}/*"'.format(d) for d in config.CONFIGURATION.ignore_dirs) if ignores: makemessages += " " + ignores # Extract strings from django source files, including .py files. make_django_cmd = makemessages + ' --extension html' execute(make_django_cmd, working_directory=config.BASE_DIR, stderr=stderr) # Extract strings from Javascript source files. make_djangojs_cmd = makemessages + ' -d djangojs --extension js' execute(make_djangojs_cmd, working_directory=config.BASE_DIR, stderr=stderr) # makemessages creates 'django.po'. This filename is hardcoded. # Rename it to django-partial.po to enable merging into django.po later. os.rename( source_msgs_dir.joinpath('django.po'), source_msgs_dir.joinpath('django-partial.po') ) # makemessages creates 'djangojs.po'. This filename is hardcoded. # Rename it to djangojs-partial.po to enable merging into djangojs.po later. os.rename( source_msgs_dir.joinpath('djangojs.po'), source_msgs_dir.joinpath('djangojs-partial.po') ) files_to_clean = set() # Extract strings from third-party applications. for app_name in config.CONFIGURATION.third_party: # Import the app to find out where it is. Then use pybabel to extract # from that directory. app_module = importlib.import_module(app_name) app_dir = path(app_module.__file__).dirname().dirname() output_file = source_msgs_dir / (app_name + ".po") files_to_clean.add(output_file) babel_cmd = 'pybabel {verbosity} extract -F {config} -c "Translators:" {app} -o {output}' babel_cmd = babel_cmd.format( verbosity=babel_verbosity, config=config.LOCALE_DIR / 'babel_third_party.cfg', app=app_name, output=output_file, ) execute(babel_cmd, working_directory=app_dir, stderr=stderr) # Segment the generated files. segmented_files = segment_pofiles("en") files_to_clean.update(segmented_files) # Finish each file. for filename in files_to_clean: LOG.info('Cleaning %s', filename) pofile = polib.pofile(source_msgs_dir.joinpath(filename)) # replace default headers with edX headers fix_header(pofile) # replace default metadata with edX metadata fix_metadata(pofile) # remove key strings which belong in messages.po strip_key_strings(pofile) pofile.save()
def run(self, args): """ Main entry point of script """ logging.basicConfig(stream=sys.stdout, level=logging.INFO) config.LOCALE_DIR.parent.makedirs_p() source_msgs_dir = config.CONFIGURATION.source_messages_dir remove_file(source_msgs_dir.joinpath('django.po')) # Extract strings from mako templates. verbosity_map = { 0: "-q", 1: "", 2: "-v", } babel_verbosity = verbosity_map.get(args.verbose, "") if args.verbose: stderr = None else: stderr = DEVNULL # --keyword informs Babel that `interpolate()` is an expected # gettext function, which is necessary because the `tokenize` function # in the `markey` module marks it as such and passes it to Babel. # (These functions are called in the django-babel-underscore module.) babel_cmd_template = ( 'pybabel {verbosity} extract --mapping={config} ' '--add-comments="Translators:" --keyword="interpolate" ' '. --output={output}') babel_mako_cfg = base(config.LOCALE_DIR, 'babel_mako.cfg') if babel_mako_cfg.exists(): babel_mako_cmd = babel_cmd_template.format( verbosity=babel_verbosity, config=babel_mako_cfg, output=base(config.CONFIGURATION.source_messages_dir, 'mako.po'), ) execute(babel_mako_cmd, working_directory=config.BASE_DIR, stderr=stderr) babel_underscore_cfg = base(config.LOCALE_DIR, 'babel_underscore.cfg') if babel_underscore_cfg.exists(): babel_underscore_cmd = babel_cmd_template.format( verbosity=babel_verbosity, config=babel_underscore_cfg, output=base(config.CONFIGURATION.source_messages_dir, 'underscore.po'), ) execute(babel_underscore_cmd, working_directory=config.BASE_DIR, stderr=stderr) makemessages = "django-admin.py makemessages -l en -v{}".format( args.verbose) ignores = " ".join('--ignore="{}/*"'.format(d) for d in config.CONFIGURATION.ignore_dirs) if ignores: makemessages += " " + ignores # Extract strings from django source files, including .py files. make_django_cmd = makemessages + ' --extension html' execute(make_django_cmd, working_directory=config.BASE_DIR, stderr=stderr) # Extract strings from Javascript source files. make_djangojs_cmd = makemessages + ' -d djangojs --extension js' execute(make_djangojs_cmd, working_directory=config.BASE_DIR, stderr=stderr) # makemessages creates 'django.po'. This filename is hardcoded. # Rename it to django-partial.po to enable merging into django.po later. os.rename(source_msgs_dir.joinpath('django.po'), source_msgs_dir.joinpath('django-partial.po')) # makemessages creates 'djangojs.po'. This filename is hardcoded. # Rename it to djangojs-partial.po to enable merging into djangojs.po later. os.rename(source_msgs_dir.joinpath('djangojs.po'), source_msgs_dir.joinpath('djangojs-partial.po')) files_to_clean = set() # Extract strings from third-party applications. for app_name in config.CONFIGURATION.third_party: # Import the app to find out where it is. Then use pybabel to extract # from that directory. app_module = importlib.import_module(app_name) app_dir = path(app_module.__file__).dirname().dirname() # pylint: disable=no-value-for-parameter output_file = source_msgs_dir / (app_name + ".po") files_to_clean.add(output_file) babel_cmd = 'pybabel {verbosity} extract -F {config} -c "Translators:" {app} -o {output}' babel_cmd = babel_cmd.format( verbosity=babel_verbosity, config=config.LOCALE_DIR / 'babel_third_party.cfg', app=app_name, output=output_file, ) execute(babel_cmd, working_directory=app_dir, stderr=stderr) # Segment the generated files. segmented_files = segment_pofiles("en") files_to_clean.update(segmented_files) # Finish each file. for filename in files_to_clean: LOG.info('Cleaning %s', filename) pofile = polib.pofile(source_msgs_dir.joinpath(filename)) # replace default headers with edX headers fix_header(pofile) # replace default metadata with edX metadata fix_metadata(pofile) # remove key strings which belong in messages.po strip_key_strings(pofile) pofile.save()
def main(): logging.basicConfig(stream=sys.stdout, level=logging.INFO) create_dir_if_necessary(LOCALE_DIR) source_msgs_dir = CONFIGURATION.source_messages_dir remove_file(source_msgs_dir.joinpath('django.po')) # Extract strings from mako templates. babel_mako_cmd = 'pybabel extract -F {config} -c "Translators:" . -o {output}' babel_mako_cmd = babel_mako_cmd.format( config=base(LOCALE_DIR, 'babel_mako.cfg'), output=base(CONFIGURATION.source_messages_dir, 'mako.po'), ) execute(babel_mako_cmd, working_directory=BASE_DIR) makemessages = "django-admin.py makemessages -l en" ignores = " ".join('--ignore="{}/*"'.format(d) for d in CONFIGURATION.ignore_dirs) if ignores: makemessages += " " + ignores # Extract strings from django source files, including .py files. make_django_cmd = makemessages + ' --extension html' execute(make_django_cmd, working_directory=BASE_DIR) # Extract strings from Javascript source files. make_djangojs_cmd = makemessages + ' -d djangojs --extension js' execute(make_djangojs_cmd, working_directory=BASE_DIR) # makemessages creates 'django.po'. This filename is hardcoded. # Rename it to django-partial.po to enable merging into django.po later. os.rename( source_msgs_dir.joinpath('django.po'), source_msgs_dir.joinpath('django-partial.po') ) # makemessages creates 'djangojs.po'. This filename is hardcoded. # Rename it to djangojs-partial.po to enable merging into djangojs.po later. os.rename( source_msgs_dir.joinpath('djangojs.po'), source_msgs_dir.joinpath('djangojs-partial.po') ) # Extract strings from third-party applications. for app_name in CONFIGURATION.third_party: # Import the app to find out where it is. Then use pybabel to extract # from that directory. app_module = importlib.import_module(app_name) app_dir = path(app_module.__file__).dirname().dirname() babel_cmd = 'pybabel extract -F {config} -c "Translators:" {app} -o {output}' babel_cmd = babel_cmd.format( config=LOCALE_DIR / 'babel_third_party.cfg', app=app_name, output=source_msgs_dir / (app_name + ".po"), ) execute(babel_cmd, working_directory=app_dir) # Segment the generated files. segmented_files = segment_pofiles("en") # Finish each file. for filename in segmented_files: LOG.info('Cleaning %s' % filename) po = pofile(source_msgs_dir.joinpath(filename)) # replace default headers with edX headers fix_header(po) # replace default metadata with edX metadata fix_metadata(po) # remove key strings which belong in messages.po strip_key_strings(po) po.save()
def run(self, args): """ Main entry point of script """ logging.basicConfig(stream=sys.stdout, level=logging.INFO) config.LOCALE_DIR.parent.makedirs_p() source_msgs_dir = config.CONFIGURATION.source_messages_dir remove_file(source_msgs_dir.joinpath("django.po")) # Extract strings from mako templates. verbosity_map = {0: "-q", 1: "", 2: "-v"} babel_verbosity = verbosity_map.get(args.verbose, "") if args.verbose: stderr = None else: stderr = DEVNULL # --keyword informs Babel that `interpolate()` is an expected # gettext function, which is necessary because the `tokenize` function # in the `markey` module marks it as such and passes it to Babel. # (These functions are called in the django-babel-underscore module.) babel_cmd_template = ( "pybabel {verbosity} extract --mapping={config} " '--add-comments="Translators:" --keyword="interpolate" ' ". --output={output}" ) babel_mako_cfg = base(config.LOCALE_DIR, "babel_mako.cfg") if babel_mako_cfg.exists(): babel_mako_cmd = babel_cmd_template.format( verbosity=babel_verbosity, config=babel_mako_cfg, output=base(config.CONFIGURATION.source_messages_dir, "mako.po"), ) execute(babel_mako_cmd, working_directory=config.BASE_DIR, stderr=stderr) babel_underscore_cfg = base(config.LOCALE_DIR, "babel_underscore.cfg") if babel_underscore_cfg.exists(): babel_underscore_cmd = babel_cmd_template.format( verbosity=babel_verbosity, config=babel_underscore_cfg, output=base(config.CONFIGURATION.source_messages_dir, "underscore.po"), ) execute(babel_underscore_cmd, working_directory=config.BASE_DIR, stderr=stderr) makemessages = "django-admin.py makemessages -l en -v{}".format(args.verbose) ignores = " ".join('--ignore="{}/*"'.format(d) for d in config.CONFIGURATION.ignore_dirs) if ignores: makemessages += " " + ignores # Extract strings from django source files, including .py files. make_django_cmd = makemessages + " --extension html" execute(make_django_cmd, working_directory=config.BASE_DIR, stderr=stderr) # Extract strings from Javascript source files. make_djangojs_cmd = makemessages + " -d djangojs --extension js" execute(make_djangojs_cmd, working_directory=config.BASE_DIR, stderr=stderr) # makemessages creates 'django.po'. This filename is hardcoded. # Rename it to django-partial.po to enable merging into django.po later. os.rename(source_msgs_dir.joinpath("django.po"), source_msgs_dir.joinpath("django-partial.po")) # makemessages creates 'djangojs.po'. This filename is hardcoded. # Rename it to djangojs-partial.po to enable merging into djangojs.po later. os.rename(source_msgs_dir.joinpath("djangojs.po"), source_msgs_dir.joinpath("djangojs-partial.po")) files_to_clean = set() # Extract strings from third-party applications. for app_name in config.CONFIGURATION.third_party: # Import the app to find out where it is. Then use pybabel to extract # from that directory. app_module = importlib.import_module(app_name) app_dir = path(app_module.__file__).dirname().dirname() # pylint: disable=no-value-for-parameter output_file = source_msgs_dir / (app_name + ".po") files_to_clean.add(output_file) babel_cmd = 'pybabel {verbosity} extract -F {config} -c "Translators:" {app} -o {output}' babel_cmd = babel_cmd.format( verbosity=babel_verbosity, config=config.LOCALE_DIR / "babel_third_party.cfg", app=app_name, output=output_file, ) execute(babel_cmd, working_directory=app_dir, stderr=stderr) # Segment the generated files. segmented_files = segment_pofiles("en") files_to_clean.update(segmented_files) # Finish each file. for filename in files_to_clean: LOG.info("Cleaning %s", filename) pofile = polib.pofile(source_msgs_dir.joinpath(filename)) # replace default headers with edX headers fix_header(pofile) # replace default metadata with edX metadata fix_metadata(pofile) # remove key strings which belong in messages.po strip_key_strings(pofile) pofile.save()