root/branches/gajim_0.8.2/scripts/translations.py

Revision 3463, 1.9 kB (checked in by nk, 3 years ago)

fix translations. py in 0.8.2

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Initially written by Nikos Kouremenos
4# Dedicated to Yann Le Boulanger
5# Usage: './translations.py [help] [stats] [update]'
6
7import os
8import sys
9
10stats = False
11update = False
12check = False
13
14def visit(arg, dirname, names):
15        if dirname.find('.svn') != -1:
16                return
17        if dirname.endswith('LC_MESSAGES'):
18                if 'gajim.po' in names:
19                        path_to_po = os.path.join(dirname, 'gajim.po')
20                        pos = path_to_po.find('po/') + 3 #3 = len('po/')
21                        endpos = path_to_po.find('/', pos)
22                        name = path_to_po[pos:endpos]
23                        if update: # update an existing po file)
24                                os.system('msgmerge -q -U ../po/'+name+'/LC_MESSAGES/gajim.po ../po/gajim.pot')
25                        if stats:
26                                print name, 'has now:'
27                                os.system('msgfmt --statistics ' + path_to_po)
28                        if check:
29                                os.system('msgfmt -c --check-accelerators="_" ' + path_to_po)
30
31def show_help():
32        print sys.argv[0], '[help] [stats] [update] [check]'
33        sys.exit(0)
34
35def update_pot():
36        # create header for glade strings
37        os.system('intltool-extract --type=gettext/glade ../src/gtkgui.glade')
38        # update the pot
39        os.system('make -C ../po/ all gajim.pot')
40        print 'gajim.pot was updated successfully'
41
42if __name__ == '__main__':
43        if os.path.basename(os.getcwd()) != 'scripts':
44                print 'run me with cwd: scripts'
45                sys.exit()
46
47        path_to_dir = '../po'
48
49        if len(sys.argv) == 2:
50                if sys.argv[1].startswith('h'):
51                        show_help()
52
53                param = sys.argv[1]
54                if param == 'stats': # stats only
55                        stats = True
56                        os.path.walk(path_to_dir, visit, None)
57                elif param == 'update': # update only
58                        update_pot()
59                        update = True
60                        os.path.walk(path_to_dir, visit, None) # update each po & no stats
61                        print 'Done'
62                elif param == 'check':
63                        check = True
64                        os.path.walk(path_to_dir, visit, None)
65
66        elif len(sys.argv) == 1: # update & stats & no check
67                update_pot()
68                update = True
69                stats = True
70                os.path.walk(path_to_dir, visit, None)
71                print 'Done'
72
73        else:
74                show_help()
Note: See TracBrowser for help on using the browser.