This repository has been archived by the owner on Apr 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
i18nmergeall.py
executable file
·92 lines (75 loc) · 2.81 KB
/
i18nmergeall.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python2.4
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Merge a POT file with all languages
This utility requires the GNU gettext package to be installed. The command
'msgmerge' will be executed for each language.
Usage: i18mergeall.py [options]
Options:
-h / --help
Print this message and exit.
-l / --locales-dir
Specify the 'locales' directory for which to generate the statistics.
$Id$
"""
import sys
import os
import getopt
def usage(code, msg=''):
"""Display help."""
print >> sys.stderr, '\n'.join(__doc__.split('\n')[:-2])
if msg:
print >> sys.stderr, '** Error: ' + str(msg) + ' **'
sys.exit(code)
def merge(path):
for language in os.listdir(path):
lc_messages_path = os.path.join(path, language, 'LC_MESSAGES')
# English is the default for Zope, so ignore it
#if language == 'en':
# continue
# Make sure we got a language directory
if not os.path.isdir(lc_messages_path):
continue
msgs = []
for domain_file in os.listdir(lc_messages_path):
if domain_file.endswith('.po'):
domain_path = os.path.join(lc_messages_path, domain_file)
pot_path = os.path.join(path, domain_file+'t')
domain = domain_file.split('.')[0]
print 'Merging language "%s", domain "%s"' %(language, domain)
os.system('msgmerge %s %s -o %s' %(
domain_path, pot_path, domain_path))
def main(argv=sys.argv):
try:
opts, args = getopt.getopt(
argv[1:],
'l:h',
['help', 'locals-dir='])
except getopt.error, msg:
usage(1, msg)
path = None
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-l', '--locales-dir'):
cwd = os.getcwd()
# This is for symlinks. Thanks to Fred for this trick.
if os.environ.has_key('PWD'):
cwd = os.environ['PWD']
path = os.path.normpath(os.path.join(cwd, arg))
if path is None:
usage(1, 'You must specify the path to the locales directory.')
merge(path)
if __name__ == '__main__':
main()