| 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 | |
|---|
| 7 | import os |
|---|
| 8 | import sys |
|---|
| 9 | |
|---|
| 10 | stats = False |
|---|
| 11 | update = False |
|---|
| 12 | check = False |
|---|
| 13 | |
|---|
| 14 | def 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 | |
|---|
| 31 | def show_help(): |
|---|
| 32 | print sys.argv[0], '[help] [stats] [update] [check]' |
|---|
| 33 | sys.exit(0) |
|---|
| 34 | |
|---|
| 35 | def 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 | |
|---|
| 42 | if __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() |
|---|