コード例 #1
0
ファイル: translate.py プロジェクト: vhuarui/ngfw_src
def main(argv):
    language_ids = Languages.get_enabled_ids()

    try:
        opts, args = getopt.getopt(argv, "hl:d",
                                   ["help", "languages=", "debug"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-l", "--languages"):
            language_ids = arg.split(",")

    for id in language_ids:
        language = Languages.get_by_id(id)
        po = i18n.PoFile(language=language["id"])
        po.load()
        print "\tProcessing: %s, %s," % (language["name"], po.file_name),
        print ""
        if language["id"] == "xx":
            process_test(po)
        else:
            process_google(po)
        po.save()
コード例 #2
0
ファイル: status.py プロジェクト: pagosasia/ngfw_src
def main(argv):
    _debug = False
    source_po_file_name = None
    language_ids = languages.get_enabled_ids()

    try:
        opts, args = getopt.getopt(argv, "hsl:d", ["help", "language=", "debug"] )
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ( "-h", "--help"):
            usage()
            sys.exit()
        elif opt in ( "-d", "--debug"):
            _debug = True
        elif opt in ( "-l", "--language"):
            language_id = arg.split(",")

    for language_id in language_ids:
        po = i18n.PoFile(language=language_id, file_name=source_po_file_name)
        po.load()

        language = languages.get_by_id(language_id)
        print("Status: %s" % (language["name"]))
        print(" file=%s," % (po.file_name))

        print(" total records=%d, updated_records=%d, completed=%2.2f%%" % ((po.total_record_count(), po.updated_record_count(), (float(po.updated_record_count()) / po.total_record_count()) * 100)))
コード例 #3
0
ファイル: validate.py プロジェクト: vhuarui/ngfw_src
def main(argv):
    """
    Main entry for generate
    """
    language_ids = Languages.get_enabled_ids()

    try:
        opts, args = getopt.getopt(argv, "hl:d",
                                   ["help", "languages=", "debug"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-l", "--languages"):
            language_ids = arg.split(",")

    for id in language_ids:
        language = Languages.get_by_id(id)
        po = i18n.PoFile(language=language["id"])
        print "\tProcessing: %s, %s," % (language["name"], po.file_name)
        po.load()
        print ""
        print "record count=%d" % (len(po.records)),
        character_count = 0
        word_count = 0
        for record in po.records:
            if record.msg_id == "":
                now = datetime.datetime.now()
                record.replace_msg_str(
                    "PO-Revision-Date:", "PO-Revision-Date: " +
                    now.strftime("%Y-%m-%d %H:%M%z") + '\\n')
            record.set_verified()
            if len("".join(record.msg_str)) == 0:
                character_count = character_count + len(record.msg_id)
                word_count = word_count + len(re.findall(
                    r'\w+', record.msg_id))
        print ", %d/%d chars/words to translate" % (character_count,
                                                    word_count)
コード例 #4
0
ファイル: collate.py プロジェクト: pagosasia/ngfw_src
def main(argv):
    """
    Main entry point for collate
    """
    base_path = None

    try:
        opts, args = getopt.getopt(argv, "hb:d",
                                   ["help", "base_path=", "debug"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-b", "--base_path"):
            base_path = arg
        elif opt in ("-l", "--language"):
            language = arg

    ngfw = i18n.Ngfw(base_path=base_path)

    #
    # Don't rely on modules; just pull all po files.
    #
    po_base_paths = []
    for search_path in ngfw.search_paths:
        for po_path in glob.glob(search_path + "/*/po"):
            po_base_paths.append(po_path)

    po_paths = []
    for po_base_path in po_base_paths:
        for root, dirs, files in os.walk(po_base_path):
            if "/i18ntools/" in root:
                # Ignore ourselves just in case we happen to have directory
                continue
            if '.svn' in dirs:
                dirs.remove(".svn")
            if 'xx' in dirs:
                dirs.remove("xx")
            if len(dirs) == 0:
                continue
            for path in dirs:
                po_paths.append(po_base_path + "/" + path)

    collated_po_files = {}
    for language in languages.get_enabled():
        collated_po_files[language["id"]] = i18n.PoFile(language["id"])

    #
    # Read individual po files and then add records into collated
    #
    language_po_total_record_counts = {}
    for po_path in po_paths:
        language = po_path[po_path.rfind("/") + 1:]
        if language == "ga":
            continue
        for po_file_name in glob.glob(po_path + "/*.po"):
            print(po_file_name, )
            po_file = i18n.PoFile(language, po_file_name)
            po_file.load()
            print("records=%d" % (len(po_file.records)))
            if not language in language_po_total_record_counts:
                language_po_total_record_counts[language] = 0
            language_po_total_record_counts[language] += len(po_file.records)
            for record in po_file.records:
                collated_po_files[language].add_record(record)

    print("Results:")
    for language in language_po_total_record_counts:
        print("language=%s, total_records=%d" %
              (language, language_po_total_record_counts[language]))

    #
    # Save collated files
    #
    for collated_po_file in collated_po_files.values():
        if collated_po_file.language == "en":
            continue
        if collated_po_file.language == "test":
            continue
        print("file=%s, non-duplicate records=%d" %
              (collated_po_file.file_name, len(collated_po_file.records)))
        collated_po_file.save()
コード例 #5
0
def main(argv):
    """
    Main entry for generate
    """
    global pot
    language_ids = languages.get_enabled_ids()

    try:
        opts, args = getopt.getopt(argv, "hpl:d",
                                   ["help", "language=", "debug"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-l", "--language"):
            language_ids = arg.split(",")

    if os.path.isfile(pot_file_name) is False:
        print "Missing template file %s" % (pot_file_name)
        sys.exit(1)

    pot.load()

    print "Synchronizing po languages..."
    total_character_count = 0
    total_word_count = 0
    for language in languages.get_enabled():
        if language["id"] == "en":
            continue

        po = i18n.PoFile(language=language["id"])
        po.load()

        diff = {
            "add":
            [x for x in pot.records if not po.get_record_by_msgid(x.msg_id)],
            "remove":
            [x for x in po.records if not pot.get_record_by_msgid(x.msg_id)]
        }
        print "  Synchronizing: %s, %s," % (language["name"], po.file_name),

        for diff_record in diff["remove"]:
            po.remove_record(diff_record)

        ## Add new and synchronize comments for existing
        for record in pot.records:
            po.add_record(record, replace_comments=True)

        print "%d added, %d removed" % (len(diff["add"]), len(diff["remove"])),

        character_count = 0
        word_count = 0
        for record in po.records:
            if record.msg_id == "":
                now = datetime.datetime.now()
                record.replace_msg_str(
                    "PO-Revision-Date:", "PO-Revision-Date: " +
                    now.strftime("%Y-%m-%d %H:%M%z") + '\\n')
            record.set_verified()
            if len("".join(record.msg_str)) == 0:
                character_count = character_count + len(record.msg_id)
                word_count = word_count + len(re.findall(
                    r'\w+', record.msg_id))
        print ", %d/%d chars/words to translate" % (character_count,
                                                    word_count)
        total_character_count = total_character_count + character_count
        total_word_count = total_word_count + word_count

        po.save()

    print
    print "%d/%d chars/words total to translate" % (total_character_count,
                                                    total_word_count)
コード例 #6
0
ファイル: generate_po.py プロジェクト: varivera/EiffelStudio
path_predefined_metrics = os.path.join(path_studio, 'metrics', 'predefined_metrics.xml')
path_eifinit = os.path.join(path_studio, 'eifinit')
path_wizards = os.path.join(path_studio, 'wizards', 'new_projects')
path_documentation = os.path.join(os.environ.get('EIFFEL_SRC'), 'Documentation')

#path_output = os.path.join(path_studio, 'lang')
path_output = os.path.join('..', 'po_files')

if not os.path.isdir(path_output):
    os.makedirs(path_output)


# extract error messages
# ----------------------

po = i18n.PoFile(os.path.join (path_output, 'errors.pot'))

# extract long error messages

for filename in os.listdir (path_help_error):
    filepath = os.path.join (path_help_error, filename)
    if os.path.isfile(filepath):
        file = open(filepath, 'r')
	# Add whole file as entry to PO file
        po.add_message(
            i18n.empty_message(
                file.read(),
                'help/error/long',
                'Long description for error ' + filename,
                '$EIFFEL_SRC/Delivery/studio/help/errors/' + filename))
        file.close()
コード例 #7
0
def main(argv):
    """
    Main entry point for collate
    """
    base_path = None

    try:
        opts, args = getopt.getopt(argv, "hb:d",
                                   ["help", "base_path=", "debug"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-b", "--base_path"):
            base_path = arg
        elif opt in ("-l", "--language"):
            language = arg

    ngfw = i18n.Ngfw(base_path=base_path)

    #
    # Don't rely on modules; just pull all po files.
    #
    po_base_paths = []
    for search_path in ngfw.search_paths:
        for po_path in glob.glob(search_path + "/i18ntools/untangleserver"):
            po_base_paths.append(po_path)

    po_paths = []
    for po_base_path in po_base_paths:
        for root, dirs, files in os.walk(po_base_path):
            if ".translation_index" in dirs:
                continue
            if "xapian" in dirs:
                continue
            if '.svn' in dirs:
                dirs.remove(".svn")
            if 'xx' in dirs:
                dirs.remove("xx")
            if len(dirs) == 0:
                continue
            for dir in dirs:
                if "templates" in dir:
                    continue
                po_paths.append(po_base_path + "/" + dir)

    collated_po_files = {}
    for po_path in po_paths:
        language_id = po_path[po_path.rindex("/") + 1:]
        collated_po_files[language_id] = i18n.PoFile(
            language_id, "untangleserver.collated/" + language_id +
            "/untangle-" + language_id + ".po")

    # print collated_po_files
    # sys.exit(1)

    #
    # Read individual po files and then add records into collated
    #
    language_po_total_record_counts = {}
    for po_path in po_paths:
        language = po_path[po_path.rfind("/") + 1:]
        for po_file_name in glob.glob(po_path + "/*.po"):
            print po_file_name,
            po_file = i18n.PoFile(language, po_file_name)
            po_file.load()
            print "records=%d" % (len(po_file.records))
            if not language in language_po_total_record_counts:
                language_po_total_record_counts[language] = 0
            language_po_total_record_counts[language] += len(po_file.records)
            for record in po_file.records:
                collated_po_files[language].add_record(record)

    print "Results:"
    for language in language_po_total_record_counts:
        print "language=%s, total_records=%d" % (
            language, language_po_total_record_counts[language])

    #
    # Save collated files
    #
    for collated_po_file in collated_po_files.values():
        if collated_po_file.language == "en":
            continue
        if collated_po_file.language == "test":
            continue
        print "file=%s, non-duplicate records=%d" % (
            collated_po_file.file_name, len(collated_po_file.records))
        collated_po_file.save()
コード例 #8
0
def main(argv):
    """
    Main entry for generate
    """
    global pot
    pootle_directory = "untangleserver"

    try:
        opts, args = getopt.getopt(argv, "hp:d",
                                   ["help", "pootle_directory=", "debug"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-p", "--pootle_directory"):
            pootle_directory = arg

    if os.path.isfile(pot_file_name) is False:
        print("Missing template file %s" % (pot_file_name))
        sys.exit(1)

    pot.load()

    ##
    ## Update with templates
    ##
    print("Synchronizing pootle languages with templates...")
    total_character_count = 0
    total_word_count = 0
    for path in glob.glob(pootle_directory + "/*"):
        language_id = path[path.rfind("/") + 1:]
        language = languages.get_by_id(language_id)
        if language == None:
            continue
        print(language_id)
        for po_file in glob.glob(path + "/*.po"):
            po = i18n.PoFile(language_id, po_file)
            po.load()

            diff = {
                "add": [
                    x for x in pot.records
                    if not po.get_record_by_msgid(x.msg_id)
                ],
                "remove": [
                    x for x in po.records
                    if not pot.get_record_by_msgid(x.msg_id)
                ]
            }
            print(
                "  Synchronizing: %s, %s," %
                (language["name"], po.file_name), )

            for diff_record in diff["remove"]:
                po.remove_record(diff_record)

            ## Add new and synchronize comments for existing
            for record in pot.records:
                po.add_record(record, replace_comments=True)

            print(
                "%d added, %d removed" %
                (len(diff["add"]), len(diff["remove"])), )

            character_count = 0
            word_count = 0
            for record in po.records:
                if record.msg_id == "":
                    now = datetime.datetime.now()
                    record.replace_msg_str(
                        "PO-Revision-Date:", "PO-Revision-Date: " +
                        now.strftime("%Y-%m-%d %H:%M%z") + '\\n')
                record.set_verified()
                if len("".join(record.msg_str)) == 0:
                    character_count = character_count + len(record.msg_id)
                    word_count = word_count + len(
                        re.findall(r'\w+', record.msg_id))
            print(", %d/%d chars/words to translate" %
                  (character_count, word_count))
            total_character_count = total_character_count + character_count
            total_word_count = total_word_count + word_count

            print(" total records=%d, updated_records=%d, completed=%2.2f%%" %
                  ((po.total_record_count(), po.updated_record_count(),
                    (float(po.updated_record_count()) /
                     po.total_record_count()) * 100)))

            po.save()

    ##
    ## Synchronize with official translations
    ##
    print("Synchronzing pootle languages with official translations...")
    language_ids = languages.get_enabled_ids()
    for language in languages.get_enabled():
        if language["id"] == "en" or language["id"] == "xx":
            continue

        official_po = i18n.PoFile(language=language["id"])
        official_po.load()

        diff = {"add": [], "remove": []}
        print(language["id"])
        pootle_po_file_names = glob.glob(pootle_directory + "/" +
                                         language["id"] + "/*.po")
        pootle_file_name = pootle_po_file_names[0]
        pootle_po = i18n.PoFile(language["id"], pootle_file_name)
        pootle_po.load()
        for o_record in official_po.records:
            if len("".join(o_record.msg_str)) == 0:
                continue
            p_record = pootle_po.get_record_by_msgid(o_record.msg_id)
            if p_record != None and len("".join(
                    p_record.msg_str)) != 0 and p_record.arguments_match(
                    ) == True:
                continue
            diff["add"].append(o_record)
        print(
            "  Synchronizing: %s, %s," %
            (language["name"], pootle_file_name), )

        ## Add non-empty
        for a_record in diff["add"]:
            pootle_po.add_record(a_record, replace_comments=True)

        print("%d added/modified" % (len(diff["add"])))

        pootle_po.save()