예제 #1
0
파일: copy_fix.py 프로젝트: DDNetPP/DDNetPP
def copy_fix(infile, delete_unused, append_missing, delete_empty):
    content = open(infile).readlines()
    trans = twlang.translations(infile)
    if delete_unused or append_missing:
        local = twlang.localizes()
    if append_missing:
        supported = []
    for tran, (start, expr, end) in trans.items():
        if delete_unused and tran not in local:
            content[start:end] = [None] * (end - start)
        if append_missing and tran in local:
            if expr or (not expr and delete_empty):
                supported.append(local.index(tran))
            else:
                content[start:end] = [None] * (end - start)
        if delete_empty and not expr:
            content[start:end] = [None] * (end - start)
    content = [line for line in content if line is not None]
    if append_missing:
        missing = [
            index for index in range(len(local)) if index not in supported
        ]
        if missing:
            if content[-1] != "\n":
                content.append("\n")
            for miss in missing:
                if local[miss][1] != "":
                    content.append("[" + local[miss][1] + "]\n")
                content.append(local[miss][0] + "\n== \n\n")
            content[-1] = content[-1][:-1]
    return "".join(content)
예제 #2
0
delete_unused = False
append_missing = False
delete_empty = False
for arg in args:
    if arg == "--delete-unused":
        delete_unused = True
    elif arg == "--append-missing":
        append_missing = True
    elif arg == "--delete-empty":
        delete_empty = True
    else:
        print("No such argument '"+arg+"'.")
        sys.exit()

content = open(infile).readlines()
trans = twlang.translations(infile)
if delete_unused or append_missing:
    local = twlang.localizes()
if append_missing:
    supported = []
for tran, (start, expr, end) in trans.iteritems():
    if delete_unused and tran not in local:
        content[start:end] = [None]*(end-start)
    if append_missing and tran in local:
        if expr or (not expr and delete_empty):
            supported.append(local.index(tran))
        else:
            content[start:end] = [None]*(end-start)
    if delete_empty and not expr:
        content[start:end] = [None]*(end-start)
content = [line for line in content if line != None]
예제 #3
0
delete_unused = False
append_missing = False
delete_empty = False
for arg in args:
    if arg == "--delete-unused":
        delete_unused = True
    elif arg == "--append-missing":
        append_missing = True
    elif arg == "--delete-empty":
        delete_empty = True
    else:
        print("No such argument '"+arg+"'.")
        sys.exit()

content = open(infile).readlines()
trans = twlang.translations(infile)
if delete_unused or append_missing:
    local = twlang.localizes()
if append_missing:
    supported = []
for tran, (start, expr, end) in trans.items():
    if delete_unused and tran not in local:
        content[start:end] = [None]*(end-start)
    if append_missing and tran in local:
        if expr or (not expr and delete_empty):
            supported.append(local.index(tran))
        else:
            content[start:end] = [None]*(end-start)
    if delete_empty and not expr:
        content[start:end] = [None]*(end-start)
content = [line for line in content if line != None]
예제 #4
0
#!/usr/bin/env python3
import os
import sys
import twlang

os.chdir(os.path.dirname(__file__) + "/../..")

if len(sys.argv) > 1:
    langs = sys.argv[1:]
else:
    langs = twlang.languages()
local = twlang.localizes()
table = []
for lang in langs:
    trans = twlang.translations(lang)
    empty = 0
    supported = 0
    unused = 0
    for tran, (_, expr, _) in trans.items():
        if not expr:
            empty += 1
        else:
            if tran in local:
                supported += 1
            else:
                unused += 1
    table.append([lang, len(trans), empty, len(local) - supported, unused])

table.sort(key=lambda l: l[3])
table = [["filename", "total", "empty", "missing", "unused"]] + table
s = [[str(e) for e in row] for row in table]
예제 #5
0
import twlang
import sys

if len(sys.argv) > 1:
    langs = sys.argv[1:]
else:
    langs = twlang.languages()
local = twlang.localizes()
table = []
for lang in langs:
    trans = twlang.translations(lang)
    empty = 0
    supported = 0
    unused = 0
    for tran, (_, expr, _) in trans.iteritems():
        if not expr:
            empty += 1
        else:
            if tran in local:
                supported += 1
            else:
                unused += 1
    table.append([lang, len(trans), empty, len(local)-supported, unused])

table.sort(key=lambda l: l[3])
table = [["filename", "total", "empty", "missing", "unused"]] + table
s = [[str(e) for e in row] for row in table]
lens = [max(map(len, col)) for col in zip(*s)]
fmt = "    ".join("{{:{}}}".format(x) for x in lens)
t = [fmt.format(*row) for row in s]
print("\n".join(t))