Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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]
if append_missing:
    missing = [index for index in range(len(local)) if index not in supported]
Ejemplo n.º 3
0
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]
if append_missing:
    missing = [index for index in range(len(local)) if index not in supported]