Menu

[2275f9]: / extract-translations.py  Maximize  Restore  History

Download this file

62 lines (45 with data), 1.8 kB

 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
#!/usr/bin/env python
from zeroinstall.injector.iface_cache import iface_cache
from zeroinstall.injector.namespaces import XMLNS_IFACE
import sys, os, codecs, urllib
import xml.sax.saxutils
from xml.dom import minidom
MAX_TEASER_LENGTH = 256
known = [line.strip() for line in file('known-interfaces')]
known.sort(key = lambda s: s.rsplit('/', 1)[1].lower())
result = codecs.open('feed-translations.c', 'w', encoding = 'utf-8')
done = set()
def escaped(s):
return s.replace('%', '%%').replace('\\', '\\\\').replace('"', '\\"').replace("'", "\\'")
assert escaped("Hello") == "Hello"
assert escaped("Hello %s") == "Hello %%s"
assert escaped('"It"') == '\\"It\\"'
def format_para(para):
"""Turn new-lines into spaces, removing any blank lines."""
lines = [l.strip() for l in para.split('\n')]
return ' '.join(filter(None, lines))
def translate(s):
if not s: return
if s in done: return
done.add(s)
lines = escaped(s).split('\n')
s = '\\n\\\n'.join(lines)
result.write('_("%s")\n' % s)
for uri in known:
print uri
assert uri.startswith('http://')
assert not uri.startswith('http://0install.net/tests/')
assert not uri.startswith('http://localhost')
iface = iface_cache.get_interface(uri)
if not iface.summary:
print >>sys.stderr, "Unreadable:", iface.uri
os.system("0launch -g -- '%s'" % uri)
continue
result.write('\n// Translations for %s (%s)\n' % (iface.get_name(), iface.uri))
translate(iface.summary)
paragraphs = [format_para(p) for p in iface.description.split('\n\n')]
translate('\n'.join(paragraphs))
result.close()
if os.system('xgettext --keyword=_ --from-code=utf-8 feed-translations.c -o feed-translations.pot'):
raise Exception('xgettext failed')
print "Created feed-translations.pot (update the header)"
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.