User:Reza1615/code03

import codecs text='\n' dict={} count=0 mypath='/home/reza/trans/' myfile=mypath+'new.po' save_myfile=mypath+'output.po'
 * 1) !/usr/bin/python
 * 2) -*- coding: utf-8  -*-
 * 3) Reza (User:reza1615) 2014
 * 4) Distributed under the terms of the CC-BY-SA 3.0.
 * 5) -*- coding: utf-8 -*-

for i in range(1,16): texts = codecs.open( mypath+'a('+str(i)+').po','r' ,'utf8' ) text+= texts.read text=text.replace(u'\r',u'') first_pages=text.split('\n\n#') for i in first_pages: i=i.strip.replace(u'\r',u'') if not i:           continue if not 'msgctxt' in i:           continue en=i.split(u'msgid "')[1].split(u'"\nmsgstr "')[0].strip       fa=i.split(u'msgstr "')[1].split(u'"\n\n')[0].strip[:-1]        if 'FUZZY!!' in fa:           continue        if not fa:           continue        if not en in dict:           dict[en]=fa my_text = codecs.open(myfile ,'r' ,'utf8' ) my_text= my_text.read old_text=my_text my_text=my_text.replace(u'\r',u) pages=my_text.split('\n\n#') count=0 for i in pages:    i=i.strip.replace(u'\r',u)    i_old=i    if not i:        continue    if not 'msgctxt' in i:        continue    new_en=i.split(u'msgid "')[1].split(u'"\nmsgstr "')[0].strip new_fa=i.split(u'msgstr "')[1].split(u'"\n\n')[0].strip[:-1]

if (not new_fa) and (new_en in dict): i=i.replace(u'msgstr ""',u'msgstr "'+dict[new_en]+'"@@@') if (not u'!!FUZZY!!' in i) and i.strip!=u'.' and i.strip!=u':': my_text=my_text.replace(i_old,i) count+=1 new_en=new_en+u'@@' if (not new_fa) and ((new_en).replace(u'.@@','') in dict): i=i.replace(u'msgstr ""',u'msgstr "'+dict[(new_en).replace(u'.@@','')]+'."@@@') if (not u'!!FUZZY!!' in i) and i.strip!=u'.' and i.strip!=u':': my_text=my_text.replace(i_old,i) count+=1 if (not new_fa) and ((new_en).replace(u':@@','') in dict): i=i.replace(u'msgstr ""',u'msgstr "'+dict[(new_en).replace(u':@@','')]+':"@@@') if (not u'!!FUZZY!!' in i) and i.strip!=u'.' and i.strip!=u':': my_text=my_text.replace(i_old,i) count+=1 print 'Edited='+str(count) count=0 top_page=old_text.split(u'"Plural-Forms:')[0]+'"Plural-Forms: nplurals=1; plural=0;\\n"'

pages_t=my_text.split(u'\n#') our_text=u'\n' for i in pages_t: if u'msgstr ""' in i:       continue if u'msgstr ":"' in i:       continue if u'FUZZY' in i:       continue

if u'@@@' in i:       our_text+=u'\n#'+i count+=1 print 'Edited After Filtering='+str(count) our_text=top_page+our_text.replace(u"@@@",u"")

with codecs.open(save_myfile ,mode = 'w',encoding = 'utf8' ) as f:   f.write(our_text)