summaryrefslogtreecommitdiffstats
path: root/build_tools/larch8/liblarch/i18n/i18n.py
blob: 28b60efbea674da3d7b1903caba9bd3d2dec0b34 (plain)
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 python2
# -*- coding: UTF-8 -*-

#2010.08.15
# Copyright 2010 Michael Towers

"""
1) Generally something like: pygettext.py -p i18n -o liblarch.pot *.py

I think poedit can do most of the processing, but the steps are:

2) cd i18n ; msginit -i liblarch.pot -l de

OR:
2a) to update a po file:

cd i18n ; msgmerge -U liblarch.po liblarch.pot

3) edit po file

4) generate binary file:
cd i18n ; msgfmt -c -v -o liblarch.mo liblarch.po

5) move the .mo file to i18n/de/LC_MESSAGES
"""

import sys, os, shutil
from subprocess import call

thisdir = os.path.dirname(os.path.realpath(__file__))
basedir = os.path.dirname(thisdir)
os.chdir(basedir)

if (len(sys.argv) < 2):
    lang = "de"
else:
    lang = sys.argv[1]
print "Generating internationalization for language '%s'\n" % lang
print "    If you wanted a different language run 'i18n.py <language>'"
print "    For example 'i18n.py fr'\n"

dirs = [""]
allpy = [os.path.join(d, "*.py") for d in dirs]
alluim = [os.path.join('uim', "*.uim")]
call(["pygettext.py", "-p", thisdir, "-o", "liblarch.pot"] + allpy + alluim)

os.chdir(thisdir)
langfile = lang + ".po"
pofile = os.path.join(lang, "LC_MESSAGES", langfile)
if os.path.isfile(pofile):
    shutil.copy(pofile, ".")
    call(["msgmerge", "-U", langfile, "liblarch.pot"])
else:
    call(["sed", "-i", "s|CHARSET|utf-8|", "liblarch.pot"])
    call(["msginit", "--no-translator", "-i", "liblarch.pot", "-l", lang])

lf = open("lang", "w")
lf.write(lang)
lf.close()

print "Now edit '%s' and then run 'i18n2.py'" % langfile