Esempio n. 1
0
    def verify_file(self, filename_or_string):
        """Verifies strings in file.

        :arg filename_or_string: filename to verify or the contents of
            a pofile as a string

        :returns: list of LintMessage objects

        :raises IOError: if the file is not a valid .po file or
            doesn't exist
        """
        po = parse_pofile(filename_or_string)
        msgs = []
        for entry in po:
            msgs.extend(self.lint_poentry(entry))
        return msgs
Esempio n. 2
0
    def verify_file(self, filename_or_string):
        """Verifies strings in file.

        :arg filename_or_string: filename to verify or the contents of
            a pofile as a string

        :returns: list of LintMessage objects

        :raises IOError: if the file is not a valid .po file or
            doesn't exist
        """
        po = parse_pofile(filename_or_string)
        msgs = []
        for entry in po:
            msgs.extend(self.lint_poentry(entry))
        return msgs
Esempio n. 3
0
def status(ctx, showuntranslated, showfuzzy, path):
    """Show status of a .po file."""
    out('dennis version {version}'.format(version=__version__))

    po_files = []
    for item in path:
        if os.path.isdir(item):
            for root, dirs, files in os.walk(item):
                po_files.extend(
                    [os.path.join(root, fn) for fn in files
                     if fn.endswith('.po')])
        else:
            po_files.append(item)

    po_files = [os.path.abspath(fn) for fn in po_files
                if fn.endswith('.po')]

    for fn in po_files:
        try:
            if not os.path.exists(fn):
                raise IOError('File "{fn}" does not exist.'.format(
                    fn=click.format_filename(fn)))

            pofile = parse_pofile(fn)
        except IOError as ioe:
            err('>>> Problem opening file: {fn}'.format(
                fn=click.format_filename(fn)))
            err(repr(ioe))
            continue

        out('')
        out(TERM.bold_green,
            '>>> Working on: {fn}'.format(fn=click.format_filename(fn)),
            TERM.normal)

        out('Metadata:')
        for key in ('Language', 'Report-Msgid-Bugs-To', 'PO-Revision-Date',
                    'Last-Translator', 'Language-Team', 'Plural-Forms'):
            if key in pofile.metadata and pofile.metadata[key]:
                out('  ', key, ': ', pofile.metadata[key])
        out('')

        if showuntranslated:
            out('Untranslated strings:')
            out('')
            for poentry in pofile.untranslated_entries():
                out(withlines(poentry.linenum, poentry.original))
                out('')

        if showfuzzy:
            out('Fuzzy strings:')
            out('')
            for poentry in pofile.fuzzy_entries():
                out(withlines(poentry.linenum, poentry.original))
                out('')

        total_words = 0
        translated_words = 0
        untranslated_words = 0
        for entry in pofile.translated_entries() + pofile.untranslated_entries():
            if not entry.translated():
                untranslated_words += len(entry.msgid.split())
            else:
                translated_words += len(entry.msgid.split())
            total_words += len(entry.msgid.split())

        total_strings = len(pofile)
        translated_total = len(pofile.translated_entries())
        fuzzy_total = len(pofile.fuzzy_entries())
        untranslated_total = len(pofile.untranslated_entries())

        out('Statistics:')
        out('  Total strings:             {}'.format(total_strings))
        out('    Translated:              {}'.format(translated_total))
        out('    Untranslated:            {}'.format(untranslated_total))
        out('    Fuzzy:                   {}'.format(fuzzy_total))
        out('  Total translateable words: {}'.format(total_words))
        out('    Translated:              {}'.format(translated_words))
        out('    Untranslated:            {}'.format(untranslated_words))
        if untranslated_words == 0:
            out('  Percentage:                100% COMPLETE!')
        else:
            out('  Percentage:                {}%'.format(
                pofile.percent_translated()))

    ctx.exit(0)
Esempio n. 4
0
def status(ctx, showuntranslated, showfuzzy, path):
    """Show status of a .po file."""
    out("dennis version {version}".format(version=__version__))

    po_files = []
    for item in path:
        if os.path.isdir(item):
            for root, dirs, files in os.walk(item):
                po_files.extend([
                    os.path.join(root, fn) for fn in files
                    if fn.endswith(".po")
                ])
        else:
            po_files.append(item)

    po_files = [os.path.abspath(fn) for fn in po_files if fn.endswith(".po")]

    for fn in po_files:
        try:
            if not os.path.exists(fn):
                raise IOError('File "{fn}" does not exist.'.format(
                    fn=click.format_filename(fn)))

            pofile = parse_pofile(fn)
        except IOError as ioe:
            err(">>> Problem opening file: {fn}".format(
                fn=click.format_filename(fn)))
            err(repr(ioe))
            continue

        out("")
        out(
            TERM.bold_green,
            ">>> Working on: {fn}".format(fn=click.format_filename(fn)),
            TERM.normal,
        )

        out("Metadata:")
        for key in (
                "Language",
                "Report-Msgid-Bugs-To",
                "PO-Revision-Date",
                "Last-Translator",
                "Language-Team",
                "Plural-Forms",
        ):
            if key in pofile.metadata and pofile.metadata[key]:
                out("  ", key, ": ", pofile.metadata[key])
        out("")

        if showuntranslated:
            out("Untranslated strings:")
            out("")
            for poentry in pofile.untranslated_entries():
                out(withlines(poentry.linenum, poentry.original))
                out("")

        if showfuzzy:
            out("Fuzzy strings:")
            out("")
            for poentry in pofile.fuzzy_entries():
                out(withlines(poentry.linenum, poentry.original))
                out("")

        total_words = 0
        translated_words = 0
        untranslated_words = 0
        for entry in pofile.translated_entries() + pofile.untranslated_entries(
        ):
            if not entry.translated():
                untranslated_words += len(entry.msgid.split())
            else:
                translated_words += len(entry.msgid.split())
            total_words += len(entry.msgid.split())

        total_strings = len(pofile)
        translated_total = len(pofile.translated_entries())
        fuzzy_total = len(pofile.fuzzy_entries())
        untranslated_total = len(pofile.untranslated_entries())

        out("Statistics:")
        out("  Total strings:             {}".format(total_strings))
        out("    Translated:              {}".format(translated_total))
        out("    Untranslated:            {}".format(untranslated_total))
        out("    Fuzzy:                   {}".format(fuzzy_total))
        out("  Total translateable words: {}".format(total_words))
        out("    Translated:              {}".format(translated_words))
        out("    Untranslated:            {}".format(untranslated_words))
        if untranslated_words == 0:
            out("  Percentage:                100% COMPLETE!")
        else:
            out("  Percentage:                {}%".format(
                pofile.percent_translated()))

    ctx.exit(0)
Esempio n. 5
0
def status(ctx, showuntranslated, path):
    """Show status of a .po file."""
    out('dennis version {version}'.format(version=__version__))

    po_files = []
    for item in path:
        if os.path.isdir(item):
            for root, dirs, files in os.walk(item):
                po_files.extend(
                    [os.path.join(root, fn) for fn in files
                     if fn.endswith('.po')])
        else:
            po_files.append(item)

    po_files = [os.path.abspath(fn) for fn in po_files
                if fn.endswith('.po')]

    for fn in po_files:
        try:
            if not os.path.exists(fn):
                raise IOError('File "{fn}" does not exist.'.format(fn=fn))

            pofile = parse_pofile(fn)
        except IOError as ioe:
            err('>>> Problem opening file: {fn}'.format(fn=fn))
            err(repr(ioe))
            continue

        out('')
        out(TERM.bold_green, '>>> Working on: {fn}'.format(fn=fn), TERM.normal)

        out('Metadata:')
        for key in ('Language', 'Report-Msgid-Bugs-To', 'PO-Revision-Date',
                    'Last-Translator', 'Language-Team', 'Plural-Forms'):
            if key in pofile.metadata and pofile.metadata[key]:
                out('  ', key, ': ', pofile.metadata[key])
        out('')

        if showuntranslated:
            out('Untranslated strings:')
            out('')
            for poentry in pofile.untranslated_entries():
                out(withlines(poentry.linenum, poentry.original))
                out('')

        total_words = 0
        translated_words = 0
        untranslated_words = 0
        for entry in pofile.translated_entries() + pofile.untranslated_entries():
            if not entry.translated():
                untranslated_words += len(entry.msgid.split())
            else:
                translated_words += len(entry.msgid.split())
            total_words += len(entry.msgid.split())

        total_strings = len(pofile)
        translated_total = len(pofile.translated_entries())
        fuzzy_total = len(pofile.fuzzy_entries())
        untranslated_total = len(pofile.untranslated_entries())

        out('Statistics:')
        out('  Total strings:             {0}'.format(total_strings))
        out('    Translated:              {0}'.format(translated_total))
        out('    Untranslated:            {0}'.format(untranslated_total))
        out('    Fuzzy:                   {0}'.format(fuzzy_total))
        out('  Total translateable words: {0}'.format(total_words))
        out('    Translated:              {0}'.format(translated_words))
        out('    Untranslated:            {0}'.format(untranslated_words))
        if untranslated_words == 0:
            out('  Percentage:                100% COMPLETE!')
        else:
            out('  Percentage:                {0}%'.format(
                pofile.percent_translated()))
    ctx.exit(0)