| 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 | name = path_to_po[pos:pos+2] |
|---|
| 22 | if update: # update an existing po file) |
|---|
| 23 | os.system('msgmerge -q -U ../po/'+name+'/LC_MESSAGES/gajim.po ../po/gajim.pot') |
|---|
| 24 | if stats: |
|---|
| 25 | print name, 'has now:' |
|---|
| 26 | os.system('msgfmt --statistics ' + path_to_po) |
|---|
| 27 | if check: |
|---|
| 28 | os.system('msgfmt -c --check-accelerators="_" ' + path_to_po) |
|---|
| 29 | |
|---|
| 30 | def show_help(): |
|---|
| 31 | print sys.argv[0], '[help] [stats] [update] [check]' |
|---|
| 32 | sys.exit(0) |
|---|
| 33 | |
|---|
| 34 | def update_pot(): |
|---|
| 35 | # create header for glade strings |
|---|
| 36 | os.system('intltool-extract --type=gettext/glade ../src/gtkgui.glade') |
|---|
| 37 | # update the pot |
|---|
| 38 | os.system('make -C ../po/ all gajim.pot') |
|---|
| 39 | print 'gajim.pot was updated successfully' |
|---|
| 40 | |
|---|
| 41 | if __name__ == '__main__': |
|---|
| 42 | if os.path.basename(os.getcwd()) != 'scripts': |
|---|
| 43 | print 'run me with cwd: scripts' |
|---|
| 44 | sys.exit() |
|---|
| 45 | |
|---|
| 46 | path_to_dir = '../po' |
|---|
| 47 | |
|---|
| 48 | if len(sys.argv) == 2: |
|---|
| 49 | if sys.argv[1].startswith('h'): |
|---|
| 50 | show_help() |
|---|
| 51 | |
|---|
| 52 | param = sys.argv[1] |
|---|
| 53 | if param == 'stats': # stats only |
|---|
| 54 | stats = True |
|---|
| 55 | os.path.walk(path_to_dir, visit, None) |
|---|
| 56 | elif param == 'update': # update only |
|---|
| 57 | update_pot() |
|---|
| 58 | update = True |
|---|
| 59 | os.path.walk(path_to_dir, visit, None) # update each po & no stats |
|---|
| 60 | print 'Done' |
|---|
| 61 | elif param == 'check': |
|---|
| 62 | check = True |
|---|
| 63 | os.path.walk(path_to_dir, visit, None) |
|---|
| 64 | |
|---|
| 65 | elif len(sys.argv) == 1: # update & stats & no check |
|---|
| 66 | update_pot() |
|---|
| 67 | update = True |
|---|
| 68 | stats = True |
|---|
| 69 | os.path.walk(path_to_dir, visit, None) |
|---|
| 70 | print 'Done' |
|---|
| 71 | |
|---|
| 72 | else: |
|---|
| 73 | show_help() |
|---|