forked from Flumotion/flumotion-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-locale-xml.py
executable file
·78 lines (68 loc) · 2.35 KB
/
gen-locale-xml.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
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L.
# Copyright (C) 2010,2011 Flumotion Services, S.A.
# All rights reserved.
#
# This file may be distributed and/or modified under the terms of
# the GNU Lesser General Public License version 2.1 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.LGPL" in the source distribution for more information.
#
# Headers in this file shall remain intact.
# this script generates a locale registry .xml file for flumotion
# languages are bundled by the two-letter code the locale identifier
# starts with
#
# usage:
# gen-locale-xml.py [gettext domain] [project name] [one or
# more language codes]
import os
import sys
def main(args):
if len(sys.argv) < 2:
sys.stderr.write('Please specify a gettext domain\n')
sys.exit(1)
if len(sys.argv) < 3:
sys.stderr.write('Please specify a project name\n')
sys.exit(1)
if len(sys.argv) < 4:
sys.stderr.write('Please specify one or more language codes\n')
sys.exit(1)
domain = sys.argv[1]
project = sys.argv[2]
codes = {} # 2-letter language -> full code
for code in sys.argv[3:]:
if len(code) < 2:
sys.stderr.write('Locale code %s is not at least 2 characters\n'
% code)
sys.exit(1)
lang = code[:2]
if not lang in codes:
codes[lang] = []
codes[lang].append(code)
print "<registry>"
print
print " <bundles>"
print
for lang in codes.keys():
print (" <bundle name=\"%s-locale-%s\" "
"under=\"localedatadir\" project=\"%s\">") % (
domain, lang, project)
print " <directories>"
print ' <directory name="locale">'
for code in codes[lang]:
print (" <filename location"
"=\"%s/LC_MESSAGES/%s.mo\" />") % (
code, domain)
print " </directory>"
print " </directories>"
print " </bundle>"
print
print " </bundles>"
print
print "</registry>"
main(sys.argv)