Exemple #1
0
    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_desktop(self, args: argparse.Namespace) -> None:
        messages_file = os.path.join(args.translations_dir, "desktop.pot")

        if args.extract_update:
            sources = args.sources.split(",")
            k = {"_cwd": args.translations_dir}
            xgettext(
                "--output=desktop.pot",
                "--language=Desktop",
                "--keyword",
                "--keyword=Name",
                "--package-version",
                args.version,
                "[email protected]",
                "--copyright-holder=Freedom of the Press Foundation",
                *sources,
                **k
            )
            sed("-i", "-e", '/^"POT-Creation-Date/d', messages_file, **k)

            if self.file_is_modified(messages_file):
                for f in os.listdir(args.translations_dir):
                    if not f.endswith(".po"):
                        continue
                    po_file = os.path.join(args.translations_dir, f)
                    msgmerge("--update", po_file, messages_file)
                log.warning("messages translations updated in " + messages_file)
            else:
                log.warning("desktop translations are already up to date")

        if args.compile:
            pos = [f for f in os.listdir(args.translations_dir) if f.endswith(".po")]
            linguas = [l[:-3] for l in pos]
            content = "\n".join(linguas) + "\n"
            linguas_file = join(args.translations_dir, "LINGUAS")
            try:
                open(linguas_file, "w").write(content)

                for source in args.sources.split(","):
                    target = source.rstrip(".in")
                    msgfmt(
                        "--desktop",
                        "--template",
                        source,
                        "-o",
                        target,
                        "-d",
                        ".",
                        _cwd=args.translations_dir,
                    )
                    self.sort_desktop_template(join(args.translations_dir, target))
            finally:
                if os.path.exists(linguas_file):
                    os.unlink(linguas_file)
Exemple #3
0
def extract_pot_file(full_p, file):
    logger.debug("extract file " + full_p)
    tmp_pot = "tmp.pot"
    merge_pot = "merge.pot"
    sh.pygettext3("-o", tmp_pot, full_p)
    old_pot = os.path.join(locale_folder, os.path.splitext(file)[0] + ".pot")
    if os.path.exists(old_pot):
        logger.debug("merge pots{} {}".format(old_pot, tmp_pot))
        sh.msgmerge("-o", merge_pot, old_pot, tmp_pot)
    # copy new pot to local folder
    else:
        merge_pot = tmp_pot
    logger.debug("copy pot file")
    sh.cp(merge_pot, old_pot)
Exemple #4
0
    def translate_desktop(self, args):
        messages_file = os.path.join(args.translations_dir, 'desktop.pot')

        if args.extract_update:
            sources = args.sources.split(',')
            k = {'_cwd': args.translations_dir}
            xgettext("--output=desktop.pot", "--language=Desktop", "--keyword",
                     "--keyword=Name", "--package-version", args.version,
                     "[email protected]",
                     "--copyright-holder=Freedom of the Press Foundation",
                     *sources, **k)
            sed('-i', '-e', '/^"POT-Creation-Date/d', messages_file, **k)

            if self.file_is_modified(messages_file):
                for f in os.listdir(args.translations_dir):
                    if not f.endswith('.po'):
                        continue
                    po_file = os.path.join(args.translations_dir, f)
                    msgmerge('--update', po_file, messages_file)
                log.warning("messages translations updated in " +
                            messages_file)
            else:
                log.warning("desktop translations are already up to date")

        if args.compile:
            pos = [
                f for f in os.listdir(args.translations_dir)
                if f.endswith('.po')
            ]
            linguas = [l[:-3] for l in pos]
            content = "\n".join(linguas) + "\n"
            open(join(args.translations_dir, 'LINGUAS'), 'w').write(content)

            for source in args.sources.split(','):
                target = source.rstrip('.in')
                msgfmt('--desktop',
                       '--template',
                       source,
                       '-o',
                       target,
                       '-d',
                       '.',
                       _cwd=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)