[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r5272 - trunk/www/utils/helpers
From: |
jcater |
Subject: |
r5272 - trunk/www/utils/helpers |
Date: |
Mon, 8 Mar 2004 18:03:17 -0600 (CST) |
Author: jcater
Date: 2004-03-08 18:03:15 -0600 (Mon, 08 Mar 2004)
New Revision: 5272
Modified:
trunk/www/utils/helpers/tools.py
Log:
added classes to read po/STATISTICS and /usr/share/iso-codes/*.tab
Modified: trunk/www/utils/helpers/tools.py
===================================================================
--- trunk/www/utils/helpers/tools.py 2004-03-08 20:58:46 UTC (rev 5271)
+++ trunk/www/utils/helpers/tools.py 2004-03-09 00:03:15 UTC (rev 5272)
@@ -11,6 +11,7 @@
self.releases = NEWS(tool)
self.readme = README(tool)
self.install = INSTALL(tool)
+ self.translations = TRANSLATIONS(tool)
# Import the src/ module, if possible
try:
@@ -157,4 +158,97 @@
file = openModuleFile(tool,'po/STATISTICS')
if not file:
print "WARNING: gnue-%s has no po/STATISTICS file" % (tool)
- file = StringIO()
+ lines = ()
+ else:
+ lines = file.readlines()
+ file.close()
+
+ self.trans = {}
+ for line in lines:
+ try:
+ lang, extra = line.strip().split(':')
+ except ValueError:
+ print "WARNING: gnue-%s/po/STATISTICS has an invalid line" % (tool)
+ continue
+
+ self.trans[lang] = trans = {'translated': 0, 'fuzzy': 0, 'untranslated':
0}
+ for extra in extra.split(','):
+ cnt, code, extra = extra.strip().split(' ',3)
+ trans[code] = float(cnt) # Must be float so python integer math
doesn't happen
+
+ def asHTML(self):
+ vals = []
+ for lang, trans in self.trans.items():
+ translated = trans['translated'] + trans['fuzzy']
+ total = translated + trans['untranslated']
+ if total:
+ pct = "%d%%" % (translated/total*100)
+ else:
+ pct = "0%"
+ vals.append('<li>%s: %s</li>' % (iso_codes.description(lang), pct))
+
+ if vals:
+ vals.sort()
+ return "<ul>" + string.join(vals,'\n') + "</ul>"
+ else:
+ return "<p>No translations available.</p>"
+
+
+ def asText(self):
+ vals = []
+ for lang, trans in self.trans.items():
+ translated = trans['translated'] + trans['fuzzy']
+ total = translated + trans['untranslated']
+ if total:
+ pct = "%d%%" % (translated*1.0/total*100.0)
+ else:
+ pct = "0%"
+ vals.append('%s: %s' % (iso_codes.description(lang), pct))
+
+ if vals:
+ vals.sort()
+ return string.join(vals,'\n')
+ else:
+ return "No translations available."
+
+#################################################
+#
+#
+class ISO_CODES:
+ def __init__(self):
+ self.countries = {}
+ self.languages = {}
+
+ try:
+ f = open('/usr/share/iso-codes/iso_3166.tab')
+ except IOError:
+ raise "This script requires the iso-codes debian package."
+
+ for line in f.readlines():
+ if line[0] == '#' or not len(line.strip()):
+ continue
+ code, name = line.strip().split('\t')
+ self.countries[code] = name.split('(')[0].strip()
+
+ f.close()
+
+ f = open('/usr/share/iso-codes/iso_639.tab')
+ for line in f.readlines():
+ if line[0] == '#' or not len(line.strip()):
+ continue
+ foo1, foo2, code, name = line.strip().split('\t')
+ self.languages[code] = name.split('(')[0].strip()
+
+ f.close()
+
+
+ def description(self, lang):
+ lang = lang.split('.')[0]
+ try:
+ lang, country = lang.split('_')
+ return "%s (%s)" % (self.languages[lang], self.countries[country])
+ except ValueError:
+ return self.languages[lang]
+
+
+iso_codes = ISO_CODES()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r5272 - trunk/www/utils/helpers,
jcater <=