[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-i18n-doc
Subject: Re: Patch for Scripty to process mimetypes xml files
From: Burkhard =?ISO-8859-1?Q?L=FCck?= <lueck () hube-lueck ! de>
Date: 2014-04-16 20:15:11
Message-ID: 1873605.ZRbzY5dx3c () parodia
[Download RAW message or body]
Am Dienstag, 15. April 2014, 21:53:30 schrieb Albert Astals Cid:
> El Dimarts, 15 d'abril de 2014, a les 14:06:28, Burkhard Lück va escriure:
> > 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
>
> I'd say
> $PO2MIMETYPEXML $xml_po_list $L10NDIR $PACKAGE $xml_file_po
> needs to be
> $PO2MIMETYPEXML $xml_file_relpath $L10NDIR $PACKAGE $xml_file_po
>
> Since xml_po_list technically could be a list of po files and
> xml_file_relpath is each of the items used in the while to loop the list.
>
> Am i correct?
>
Yes, fixed in the updated patch and moved inside the correct loop.
> Besides l10n-kde4/scripts/po2mimetypexml.py looks tremendously scary (and
> misses a copyright notice+license) Is there any way you can use Chusslove's
> pology tools to read the .po files? Would that be easier/more
> maitainable/more tested?
>
I have used the package python-polib now. Nothing against pology, it was just
the easiest and fastest solution for me.
Thanks
--
Burkhard Lück
["patch-mimetypes-xml.diff" (patch-mimetypes-xml.diff)]
Index: scripts/extract-xml.sh
===================================================================
--- scripts/extract-xml.sh (Revision 1384343)
+++ scripts/extract-xml.sh (Arbeitskopie)
@@ -33,9 +33,11 @@
echo "Empty preprocessed XML file: $xml_in_file !"
fi
rm -rf $xml_podir
+ $PO2MIMETYPEXML $xml_file_relpath $L10NDIR $PACKAGE $xml_file_po
else
echo "$xml_podir exists!"
fi
+ svn commit $SVNQUIETFLAG -m "update $xml_po_list" $xml_po_list
done
fi
exit_code=$?
Index: scripts/po2mimetypexml.py
===================================================================
--- scripts/po2mimetypexml.py (Revision 0)
+++ scripts/po2mimetypexml.py (Revision 0)
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys, os, glob, re, codecs
+import polib
+
+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=polib.pofile(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=''
+ for entry in pofiledict[lang].translated_entries():
+ if entry.msgid == msgid:
+ msgstr=entry.msgstr
+ break
+ 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: scripts/update_translations
===================================================================
--- scripts/update_translations (Revision 1384343)
+++ 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