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 make_dummy(filename, locale, converter): """ Takes a source po file, reads it, and writes out a new po file in :param locale: containing a dummy translation. """ if not path(filename).exists(): raise IOError('File does not exist: %r' % filename) pofile = polib.pofile(filename) for msg in pofile: converter.convert_msg(msg) # Apply declaration for English pluralization rules so that ngettext will # do something reasonable. pofile.metadata['Plural-Forms'] = 'nplurals=2; plural=(n != 1);' new_file = new_filename(filename, locale) create_dir_if_necessary(new_file) pofile.save(new_file)
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(file, locale): """ Takes a source po file, reads it, and writes out a new po file in :param locale: containing a dummy translation. """ if not os.path.exists(file): raise IOError('File does not exist: %s' % file) pofile = polib.pofile(file) converter = Dummy() for msg in pofile: converter.convert_msg(msg) # Apply declaration for English pluralization rules so that ngettext will # do something reasonable. pofile.metadata['Plural-Forms'] = 'nplurals=2; plural=(n != 1);' new_file = new_filename(file, locale) create_dir_if_necessary(new_file) pofile.save(new_file)
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(file, locale): """ Takes a source po file, reads it, and writes out a new po file in :param locale: containing a dummy translation. """ if not os.path.exists(file): raise IOError('File does not exist: %s' % file) pofile = polib.pofile(file) converter = Dummy() for msg in pofile: converter.convert_msg(msg) # If any message has a plural, then the file needs plural information. # Apply declaration for English pluralization rules so that ngettext will # do something reasonable. if any(m.msgid_plural for m in pofile): pofile.metadata['Plural-Forms'] = 'nplurals=2; plural=(n != 1);' new_file = new_filename(file, locale) create_dir_if_necessary(new_file) pofile.save(new_file)
def make_dummy(filename, locale, converter): """ Takes a source po file, reads it, and writes out a new po file in :param locale: containing a dummy translation. """ if not path(filename).exists(): raise IOError('File does not exist: %r' % filename) pofile = polib.pofile(filename) for msg in pofile: # Some strings are actually formatting strings, don't dummy-ify them, # or dates will look like "DÀTÉ_TÌMÉ_FÖRMÀT Ⱡ'σ# EST" if re.match(r"^[A-Z_]+_FORMAT$", msg.msgid): continue converter.convert_msg(msg) # Apply declaration for English pluralization rules so that ngettext will # do something reasonable. pofile.metadata['Plural-Forms'] = 'nplurals=2; plural=(n != 1);' new_file = new_filename(filename, locale) create_dir_if_necessary(new_file) pofile.save(new_file)
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(): 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()