~cypheon/elfelli

ref: 0.3.1 elfelli/i18n.py -rwxr-xr-x 1.3 KiB
ea773c78 — Johann Rudloff Use "Variables" instead of "Options" to fix SCons warning. 11 years ago
                                                                                
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
#!/usr/bin/env python

"""This is the i18n helper script for Elfelli

Usage:
./i18n.py update                Update po and pot files.
./i18n.py init <locale> ...     Initialise translations.
"""

import os, sys
from glob import glob

def find_locales():
    po_files = glob('po/*.po')
    locales = [file[3:-3] for file in po_files]
    return locales

def update_pot():
    print 'Updating po/elfelli.pot...'
    os.system('xgettext -o po/elfelli.pot -kN_ -k_ --c++ src/*.cpp src/*.h')

def update_po_files(locales):
    print 'Updating po files...'
    for lang in locales:
        os.system('msgmerge --update po/%s.po po/elfelli.pot' % lang)

def init_translation(locale):
    print 'Initialising %s locale...' % locale
    os.system('msginit -i po/elfelli.pot -o po/%s.po' % locale)

if __name__ == '__main__':
    locales = find_locales()
    if (len(sys.argv) >= 2) and (sys.argv[1] == 'update'):
        update_pot()
        update_po_files(locales)

    elif (len(sys.argv) >= 3) and (sys.argv[1] == 'init'):
        update_pot()
        for locale in sys.argv[2:]:
            if not (locale in locales):
                init_translation(locale)
            else:
                print "A '%s' translation already exists!" % locale
            locales = find_locales()

    else:
        print __doc__