User:Reza1615/code02

From translatewiki.net
Jump to: navigation, search

<source lang='python'>

  1. !/usr/bin/python
  2. -*- coding: utf-8 -*-
  3. Reza (User:reza1615)
  4. Distributed under the terms of the CC-BY-SA 3.0 .
  5. -*- coding: utf-8 -*-

import codecs text='\n'

for i in range(1,31):

   my_text = codecs.open( 'a ('+str(i)+').txt','r' ,'utf8' )
   text+= my_text.read()

text=text.replace(u'@@@\n@@@',u'@@@')

pages=text.split('@@@') dict={} count=0 for i in pages:

   i=i.strip()
   if not i:
       continue
   fa=i.split(u'falink=')[1].split(u'\n@@@')[0]
   #fa=fa.replace(u'\n',r'\n')
   en=i.split(u'enlink=')[1].split(u'falink=')[0]
   #en=en.replace(u'\n',r'\n')
   if 'FUZZY!!' in fa:
      continue
   if not en in dict:
      dict[en]=fa

myfile='out-wikimania-scholarships-app_fa (1).po'

my_text = codecs.open(myfile ,'r' ,'utf8' ) my_text= my_text.read() pages=my_text.split('\n\n') 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+u'\n' in dict):
      if not 'FUZZY!!' in dict[new_en+u'\n']:
          i=i.replace(u'msgstr ""',u'msgstr "'+dict[new_en+u'\n']+'"')
          my_text=my_text.replace(i_old,i)
   if (not new_fa) and ((new_en+u'\n').replace(u'.\n','\n') in dict):
      if not 'FUZZY!!' in dict[(new_en+u'\n').replace(u'.\n','\n')]:
          i=i.replace(u'msgstr ""',u'msgstr "'+dict[(new_en+u'\n').replace(u'.\n','\n')]+'."')
          my_text=my_text.replace(i_old,i)
   if (not new_fa) and ((new_en+u'\n').replace(u':\n','\n') in dict):
      if not 'FUZZY!!' in dict[(new_en+u'\n').replace(u':\n','\n')]:
          i=i.replace(u'msgstr ""',u'msgstr "'+dict[(new_en+u'\n').replace(u':\n','\n')]+':"')
          my_text=my_text.replace(i_old,i)

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

   f.write(my_text)