def take_action(self, parsed_args):
        statistic = []
        total = 0
        translated = 0

        main = ['/intro/', '/howto/', '/ref/', '/faq/', '/topics/']
        exclude = ['/releases/', '/internals/']
        main_total = 0
        main_translated = 0

        for path, dirs, files in os.walk(self.app.locale_path):
            for f in files:
                if f.endswith('.po'):
                    po_path = os.path.join(path, f)
                    po = pofile(po_path)

                    name = po_path[len(self.app.locale_path):]

                    excluded = False
                    for item in exclude:
                        if name.startswith(item):
                            excluded = True
                            break

                    if excluded:
                        continue

                    msg_total = len([e for e in po if not e.obsolete])
                    msg_translated = len(po.translated_entries())
                    untranslated_count = msg_total - msg_translated
                    total += msg_total
                    translated += msg_translated

                    statistic.append((unicode(name), po.percent_translated(),
                                      untranslated_count))

                    for item in main:
                        if name.startswith(item):
                            main_total += msg_total
                            main_translated += msg_translated
                            break

        self.save_to_file({
            'statistic':
            statistic,
            'total':
            '%.02f' % ((100.00 / float(total)) * translated),
            'main_total':
            '%.02f' % ((100.00 / float(main_total)) * main_translated)
        })

        self.app.stdout.write('Complete statistic generated!\n')
    def take_action(self, parsed_args):
        statistic = []
        total = 0
        translated = 0

        main = ['/intro/', '/howto/', '/ref/', '/faq/', '/topics/']
        exclude = ['/releases/', '/internals/']
        main_total = 0
        main_translated = 0

        for path, dirs, files in os.walk(self.app.locale_path):
            for f in files:
                if f.endswith('.po'):
                    po_path = os.path.join(path, f)
                    po = pofile(po_path)

                    name = po_path[len(self.app.locale_path):]

                    excluded = False
                    for item in exclude:
                        if name.startswith(item):
                            excluded = True
                            break

                    if excluded:
                        continue

                    msg_total = len([e for e in po if not e.obsolete])
                    msg_translated = len(po.translated_entries())
                    untranslated_count = msg_total - msg_translated
                    total += msg_total
                    translated += msg_translated

                    statistic.append((unicode(name),  po.percent_translated(), untranslated_count))

                    for item in main:
                        if name.startswith(item):
                            main_total += msg_total
                            main_translated += msg_translated
                            break

        self.save_to_file({
            'statistic': statistic,
            'total': '%.02f' % ((100.00 / float(total)) * translated),
            'main_total': '%.02f' % ((100.00 / float(main_total)) * main_translated)
        })

        self.app.stdout.write('Complete statistic generated!\n')
    def take_action(self, parsed_args):
        TRANSLATION_PATH = os.path.join(self.app.doc_path, "_build/translation")

        if os.path.exists(TRANSLATION_PATH):
            shutil.rmtree(TRANSLATION_PATH)
        os.system("sphinx-build -b gettext %s %s" % (self.app.doc_path, TRANSLATION_PATH))

        for path, dirs, files in os.walk(TRANSLATION_PATH):
            for f in files:
                if not f.endswith(".pot"):
                    continue

                pot_path = os.path.join(path, f)
                p = pot_path[len(TRANSLATION_PATH) + 1 : -1]
                po_path = os.path.join(self.app.locale_path, p)

                if not os.path.exists(os.path.dirname(po_path)):
                    os.makedirs(os.path.dirname(po_path))

                if not os.path.exists(po_path):
                    os.system("msginit -i %s -o %s -l ru --no-translator" % (pot_path, po_path))
                else:
                    os.system("msgmerge %s %s -U" % (po_path, pot_path))

        for path, dirs, files in os.walk(self.app.locale_path):
            for po_name in files:
                if not po_name.endswith(".po"):
                    continue

                po_path = os.path.join(path, po_name)
                po_relative_name = po_path[len(self.app.locale_path) + 1 :]
                pot_name = po_relative_name + "t"
                pot_path = os.path.join(TRANSLATION_PATH, pot_name)

                if not os.path.exists(pot_path):
                    po = pofile(po_path)
                    if po.percent_translated() != 0:
                        self.app.stdout.write(
                            "WARNING! Removed file %s with %s%% complete\n"
                            % (po_relative_name, po.percent_translated())
                        )
                    os.remove(po_path)
Example #4
0
    def take_action(self, parsed_args):
        TRANSLATION_PATH = os.path.join(self.app.doc_path, '_build/translation')

        shutil.rmtree(TRANSLATION_PATH)
        os.system('sphinx-build -b gettext %s %s' % (self.app.doc_path, TRANSLATION_PATH))

        for path, dirs, files in os.walk(TRANSLATION_PATH):
            for f in files:
                if not f.endswith('.pot'):
                    continue

                pot_path = os.path.join(path, f)
                p = pot_path[len(TRANSLATION_PATH) + 1:-1]
                po_path = os.path.join(self.app.locale_path, p)

                if not os.path.exists(os.path.dirname(po_path)):
                    os.makedirs(os.path.dirname(po_path))

                if not os.path.exists(po_path):
                    os.system('msginit -i %s -o %s -l ru --no-translator' % (pot_path, po_path))
                else:
                    os.system('msgmerge %s %s -U' % (po_path, pot_path))

        for path, dirs, files in os.walk(self.app.locale_path):
            for po_name in files:
                if not po_name.endswith('.po'):
                    continue

                po_path = os.path.join(path, po_name)
                po_relative_name = po_path[len(self.app.locale_path) + 1:]
                pot_name = po_relative_name + 't'
                pot_path = os.path.join(TRANSLATION_PATH, pot_name)

                if not os.path.exists(pot_path):
                    po = pofile(po_path)
                    if po.percent_translated() != 0:
                        self.app.stdout.write('WARNING! Removed file %s with %s%% complete\n' % (po_relative_name, po.percent_translated()))
                    os.remove(po_path)