forked from bleachbit/bleachbit-misc
/
summarize_translations.py
executable file
·97 lines (83 loc) · 2.91 KB
/
summarize_translations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
# vim: ts=4:sw=4:expandtab
# Copyright (C) 2014 by Andrew Ziem. All rights reserved.
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
# This is free software: you are free to change and redistribute it.
# There is NO WARRANTY, to the extent permitted by law.
#
#
import gettext
import os
import os.path
import re
import subprocess
import sys
dir_bb_root = os.path.abspath('../bleachbit')
dir_bb_locale = os.path.abspath('../bleachbit/locale')
dir_bb_po = os.path.abspath('../bleachbit/po')
os.chdir(dir_bb_root)
sys.path.append(dir_bb_root)
import setup
import bleachbit.Unix
gettext.bindtextdomain('bleachbit', dir_bb_locale)
gettext.textdomain('bleachbit')
gettext.install('bleachbit', dir_bb_locale, unicode=1)
strs = [
'Delete',
'Unnecessary file cleaner',
'Free space and maintain privacy',
'Program to clean unnecessary files',
'translator-credits']
summary_str = 'Free space and maintain privacy'
def get_translation_progress(lang):
"""Get the progress for a translation"""
assert (isinstance(lang, str))
oldcwd = os.getcwd()
os.chdir(dir_bb_po)
args = ['msgfmt', '--statistics', '-o', lang + '.mo', lang + '.po']
outputs = subprocess.Popen(
args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
output = outputs[1]
os.chdir(oldcwd)
# 53 translated messages, 82 untranslated messages.
match = re.search(
'([0-9]+) translated messages.* ([0-9]+) untranslated message', output)
if match:
# you should run 'make refresh-po' to update untranslated
translated = int(match.group(1))
untranslated = int(match.group(2))
return "%.0f%%" % (100. * translated / (untranslated + translated))
match = re.search('([0-9]+) translated messages', output)
if match:
return "100%"
sys.stderr.write("Unknown output for language '%s': '%s'" % (lang, output))
return "?"
def main():
print """
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
"""
print '<table>\n'
print '<tr><td>Code</td><td>Name</td><td>Percentage translated</td><td>"%s"</td></tr>\n' % summary_str
for langid in sorted(setup.supported_languages()):
assert (isinstance(langid, str))
print '<tr lang="%s">' % (langid)
native_name = bleachbit.Unix.locales.native_name(langid)
print '<td>%s</td>' % langid
print '<td>%s</td>' % (native_name)
lang = gettext.translation(
'bleachbit', localedir=dir_bb_locale, languages=[langid])
lang.install()
stats = get_translation_progress(langid)
print '<td>%s</td>' % (stats)
free_space = lang.gettext(summary_str)
# print 'free_space =', free_space
if free_space == summary_str:
free_space = ' '
print '<td>%s</td>' % free_space
print '</tr>'
print '</table>'
main()