[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-i18n-doc
Subject: Patch for Scripty to process mimetypes xml files
From: Burkhard =?ISO-8859-1?Q?L=FCck?= <lueck () hube-lueck ! de>
Date: 2014-04-15 12:06:28
Message-ID: 2103493.Rhxs38Cg2g () parodia
[Download RAW message or body]
Hi,
attached a patch for Scripty to process mimetypes xml files.
It consists of two parts:
* a python file with a simple class to read translations from a po file
the class is really simple, but should be sufficient for the task
* some modifications for the bash scripts extract-xml.sh + update_translations
this needs heavy review, my bash skills and understanding is very limited
Thanks
--
Burkhard Lück
["patch-mimetypes-xml.diff" (patch-mimetypes-xml.diff)]
Index: l10n-kde4/scripts/po2mimetypexml.py
===================================================================
--- l10n-kde4/scripts/po2mimetypexml.py (Revision 0)
+++ l10n-kde4/scripts/po2mimetypexml.py (Revision 0)
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys, os, glob, re, codecs
+
+class message_catalog_simple(): #no plurals, no ctxt, no prev, only msgid + msgstr + \
fuzzy status + def __init__(self,filename):
+ self.filename=os.path.abspath(filename)
+ self.name=os.path.basename(filename)
+ self.load()
+ def load(self):
+ f=codecs.open(self.filename,"r","utf8").read()
+ f=f.rstrip()+'\n' # >1 whitespaces (newlines etc) at end of file
+ try: f,obsoletemsg=f.split('\n#~ ',1) #falsch für "\n\n#, fuzzy\n#~ msgid \
..." "\n\n#, Tag foo\n#~ msgid ..." + except: pass
+ s=re.split('\n[:space:]*\n+',f) #2 oder mehrere '\n\n' + `\n \n'
+ if s[-1]!='' and not('msgstr' in s[-1] and 'msgid' in s[-1]): #s[-1] = #, \
fuzzy oder # Tag foo für obsolete + s=s[:-1]
+ self.comraw, self.msgstr, self.msgid = [], [], []
+ for i in s:
+ commsgid=i.split('\nmsgstr')[0]
+ msgraw =i.split('\nmsgstr')[1:]
+ com = commsgid.split('\nmsgid')[0]
+ self.comraw.append(com)
+ midraw = (commsgid.split('\nmsgid')[1:])
+ if midraw == []: midraw = (commsgid.split('msgid')[1:]) #für pos nur \
mit msgid+msgstr zeilen, ohne #-zeilen davor + \
mid=''.join(midraw).lstrip() + mid=mid.replace('\\"', "\\'")
+ mid=mid.replace('\n','').replace('"','')
+ mid=mid.replace("\\'", '\\"')
+ msg=''.join(msgraw).lstrip()
+ msg=msg.replace('\\"', "\\'")
+ msg=msg.replace('\n','').replace('"','')
+ msg=msg.replace("\\'", '\\"')
+ self.msgid.append(mid)
+ self.msgstr.append(msg)
+ def messagerange(self):
+ return range(1,len(self.comraw))
+ def is_fuzzy(self, nr):
+ if '#, fuzzy' in self.comraw[nr]:
+ return True
+ else:
+ return False
+ def get_msgstr(self, msgid):
+ msgstr=''
+ for nr in self.messagerange():
+ if self.msgid[nr]==msgid:
+ if self.is_fuzzy(nr):
+ msgstr=''
+ else:
+ msgstr=self.msgstr[nr]
+ return msgstr
+
+if len(sys.argv) != 5:
+ print '\nUsage: python %s path/to/xmlfile path/to/l10ndir/ l10nmodulename \
pofilename.po' %os.path.basename(sys.argv[0]) +else:
+ xmlfilepath, xmlfilename, l10ndirpath, l10nmodulename, pofilename = sys.argv[1], \
sys.argv[1].split("/")[-1], sys.argv[2], sys.argv[3], sys.argv[4] + \
begincommenttag="<comment>" + endcommenttag="</comment>"
+ begincommentlangtag='<comment xml:lang='
+
+ xmllines=codecs.open(xmlfilepath,"rb","utf8").readlines()
+ xmlwithtranslation=''
+ xmlpofilelist=glob.glob("%s/*/messages/%s/%s" %(l10ndirpath, l10nmodulename, \
pofilename)) +
+ pofiledict={}
+ for pofile in xmlpofilelist:
+ langcode=pofile.split(l10ndirpath)[1].split("/")[0]
+ if langcode != "x-test":
+ po=message_catalog_simple(pofile)
+ pofiledict[langcode]=po
+
+ for line in xmllines:
+ if begincommenttag in line:
+ indentwidth=line.split(begincommenttag)[0]
+ xmlwithtranslation += line
+ msgid=line.split(begincommenttag)[1].split(endcommenttag)[0]
+ for lang, po in sorted(pofiledict.iteritems()):
+ msgstr=pofiledict[lang].get_msgstr(msgid)
+ if msgstr!='':
+ transline='%s%s"%s">%s%s\n' %(indentwidth, begincommentlangtag, lang, \
msgstr, endcommenttag) + xmlwithtranslation += transline
+ elif begincommentlangtag in line:
+ pass
+ else:
+ xmlwithtranslation += line
+
+ modifiedxml=codecs.open("%s" %xmlfilepath,"w","utf8") # how to check for valid \
xml? + modifiedxml.write(xmlwithtranslation)
+ modifiedxml.close()
Index: l10n-kde4/scripts/extract-xml.sh
===================================================================
--- l10n-kde4/scripts/extract-xml.sh (Revision 1384186)
+++ l10n-kde4/scripts/extract-xml.sh (Arbeitskopie)
@@ -36,6 +36,8 @@
else
echo "$xml_podir exists!"
fi
+ $PO2MIMETYPEXML $xml_po_list $L10NDIR $PACKAGE $xml_file_po
+ svn commit $SVNQUIETFLAG -m "update $xml_po_list" $xml_po_list
done
fi
exit_code=$?
Index: l10n-kde4/scripts/update_translations
===================================================================
--- l10n-kde4/scripts/update_translations (Revision 1384186)
+++ l10n-kde4/scripts/update_translations (Arbeitskopie)
@@ -200,6 +200,8 @@
( XGETTEXT=`which xgettext` \
PACKAGE=$mod \
+ PO2MIMETYPEXML="python $BASEDIR/$transmod/scripts/po2mimetypexml.py" \
+ L10NDIR=$BASEDIR/$transmod \
bash $BASEDIR/$transmod/scripts/extract-xml.sh)
( XGETTEXT=`which xgettext` \
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic