2
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
4
Manage translation of user visible strings.
6
import shutil, tarfile, re, os, subprocess, urllib2
9
'aa':'Afar','ab':'Abkhazian','af':'Afrikaans','am':'Amharic','ar':'Arabic','as':'Assamese','ay':'Aymara','az':'Azerbaijani',
10
'ba':'Bashkir','be':'Byelorussian','bg':'Bulgarian','bh':'Bihari','bi':'Bislama','bn':'Bengali','bo':'Tibetan','br':'Breton',
11
'ca':'Catalan','co':'Corsican','cs':'Czech','cy':'Welsh',
12
'da':'Danish','de':'German','dz':'Bhutani',
13
'el':'Greek','en':'English','eo':'Esperanto','es':'Spanish','et':'Estonian','eu':'Basque',
14
'fa':'Persian','fi':'Finnish','fj':'Fiji','fo':'Faroese','fr':'French','fy':'Frisian',
15
'ga':'Irish','gd':'Scots Gaelic','gl':'Galician','gn':'Guarani','gu':'Gujarati',
16
'ha':'Hausa','he':'Hebrew','hi':'Hindi','hr':'Croatian','hu':'Hungarian','hy':'Armenian',
17
'ia':'Interlingua','id':'Indonesian','ie':'Interlingue','ik':'Inupiak','is':'Icelandic','it':'Italian','iu':'Inuktitut',
18
'ja':'Japanese','jw':'Javanese',
19
'ka':'Georgian','kk':'Kazakh','kl':'Greenlandic','km':'Cambodian','kn':'Kannada','ko':'Korean','ks':'Kashmiri','ku':'Kurdish','ky':'Kirghiz',
20
'la':'Latin','ln':'Lingala','lo':'Laothian','lt':'Lithuanian','lv':'Latvian, Lettish',
21
'mg':'Malagasy','mi':'Maori','mk':'Macedonian','ml':'Malayalam','mn':'Mongolian','mo':'Moldavian','mr':'Marathi','ms':'Malay','mt':'Maltese','my':'Burmese',
22
'na':'Nauru','nb':'Norwegian Bokmal','nds':'German,Low','ne':'Nepali','nl':'Dutch','no':'Norwegian',
23
'oc':'Occitan','om':'(Afan) Oromo','or':'Oriya',
24
'pa':'Punjabi','pl':'Polish','ps':'Pashto, Pushto','pt':'Portuguese',
26
'rm':'Rhaeto-Romance','rn':'Kirundi','ro':'Romanian','ru':'Russian','rw':'Kinyarwanda',
27
'sa':'Sanskrit','sd':'Sindhi','sg':'Sangho','sh':'Serbo-Croatian','si':'Sinhalese','sk':'Slovak','sl':'Slovenian','sm':'Samoan','sn':'Shona','so':'Somali','sq':'Albanian','sr':'Serbian','ss':'Siswati','st':'Sesotho','su':'Sundanese','sv':'Swedish','sw':'Swahili',
28
'ta':'Tamil','te':'Telugu','tg':'Tajik','th':'Thai','ti':'Tigrinya','tk':'Turkmen','tl':'Tagalog','tn':'Setswana','to':'Tonga','tr':'Turkish','ts':'Tsonga','tt':'Tatar','tw':'Twi',
29
'ug':'Uighur','uk':'Ukrainian','ur':'Urdu','uz':'Uzbek',
30
'vi':'Vietnamese','vo':'Volapuk',
33
'yi':'Yiddish','yo':'Yoruba',
34
'za':'Zhuang','zh':'Chinese','zu':'Zulu'
38
def import_from_launchpad(url):
39
f = open('/tmp/launchpad_export.tar.gz', 'wb')
40
shutil.copyfileobj(urllib2.urlopen(url), f)
42
tf = tarfile.open('/tmp/launchpad_export.tar.gz', 'r:gz')
44
while next is not None:
45
if next.isfile() and next.name.endswith('.po'):
47
po = re.search(r'-([a-z]{2,3}\.po)', next.name).group(1)
51
out = os.path.abspath(os.path.join('.', os.path.basename(po)))
52
print 'Updating', '%6s'%po, '-->', out
53
open(out, 'wb').write(tf.extractfile(next).read())
55
check_for_critical_bugs()
56
path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
58
subprocess.check_call('python setup.py translations'.split(), cwd=path)
61
def check_for_critical_bugs():
62
if os.path.exists('.errors'):
63
shutil.rmtree('.errors')
64
pofilter = ('pofilter', '-i', '.', '-o', '.errors',
65
'-t', 'accelerators', '-t', 'escapes', '-t', 'variables',
67
subprocess.check_call(pofilter)
68
errs = os.listdir('.errors')
70
print 'WARNING: Translation errors detected'
71
print 'See the .errors directory and http://translate.sourceforge.net/wiki/toolkit/using_pofilter'
73
if __name__ == '__main__':
75
import_from_launchpad(sys.argv[1])