import sys,os
# python3 mergetr.py lc... : tr/<lc>.part + tr/<lc>.new -> tr/<lc>.txt (sorted by id)
for lc in sys.argv[1:]:
    d={}
    for ext in ('part','new'):
        p=f'tr/{lc}.{ext}'
        if os.path.exists(p):
            for l in open(p,encoding='utf8'):
                l=l.rstrip('\n')
                if l.strip(): i,t=l.split('|',1); d[int(i)]=t
    open(f'tr/{lc}.txt','w',encoding='utf8').write('\n'.join('%d|%s'%(i,d[i]) for i in sorted(d))+'\n')
    print(lc,len(d))
