def translate_messages(self, args: argparse.Namespace) -> None: messages_file = os.path.join(args.translations_dir, 'messages.pot') if args.extract_update: if not os.path.exists(args.translations_dir): os.makedirs(args.translations_dir) sources = args.sources.split(',') pybabel.extract( '--charset=utf-8', '--mapping', args.mapping, '--output', messages_file, '--project=SecureDrop', '--version', args.version, "[email protected]", "--copyright-holder=Freedom of the Press Foundation", *sources) sed('-i', '-e', '/^"POT-Creation-Date/d', messages_file) if (self.file_is_modified(messages_file) and len(os.listdir(args.translations_dir)) > 1): tglob = '{}/*/LC_MESSAGES/*.po'.format(args.translations_dir) for translation in glob.iglob(tglob): msgmerge('--previous', '--update', translation, messages_file) log.warning("messages translations updated in {}".format( messages_file)) else: log.warning("messages translations are already up to date") if args.compile and len(os.listdir(args.translations_dir)) > 1: pybabel.compile('--directory', args.translations_dir)
def translate_messages(self, args: argparse.Namespace) -> None: messages_file = os.path.join(args.translations_dir, "messages.pot") if args.extract_update: if not os.path.exists(args.translations_dir): os.makedirs(args.translations_dir) sources = args.sources.split(",") pybabel.extract( "--charset=utf-8", "--mapping", args.mapping, "--output", messages_file, "--project=SecureDrop", "--version", args.version, "[email protected]", "--copyright-holder=Freedom of the Press Foundation", "--add-comments=Translators:", "--strip-comments", "--add-location=never", "--no-wrap", *sources ) sed("-i", "-e", '/^"POT-Creation-Date/d', messages_file) if self.file_is_modified(messages_file) and len(os.listdir(args.translations_dir)) > 1: tglob = "{}/*/LC_MESSAGES/*.po".format(args.translations_dir) for translation in glob.iglob(tglob): msgmerge("--previous", "--update", "--no-wrap", translation, messages_file) log.warning("messages translations updated in {}".format(messages_file)) else: log.warning("messages translations are already up to date") if args.compile and len(os.listdir(args.translations_dir)) > 1: pybabel.compile("--directory", args.translations_dir)