-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18n.py
executable file
·105 lines (89 loc) · 3.85 KB
/
i18n.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# ocitysmap, city map and street index generator from OpenStreetMap data
# Copyright (C) 2009 David Decotigny
# Copyright (C) 2009 Frédéric Lehobey
# Copyright (C) 2009 David Mentré
# Copyright (C) 2009 Maxime Petazzoni
# Copyright (C) 2009 Thomas Petazzoni
# Copyright (C) 2009 Gaël Utard
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import shutil
import optparse
import subprocess
def make_pot():
print "Make locale/ocitysmap.pot"
subprocess.check_call(['xgettext', '-o', 'ocitysmap.pot', '-p', 'locale',
'-L', 'Python',
'ocitysmap2/indexlib/indexer.py',
'ocitysmap2/layoutlib/multi_page_renderer.py',
'ocitysmap2/layoutlib/single_page_renderers.py'])
return
def make_po(languages):
print "Merge locale/ocitysmap.pot into locale/*/LC_MESSAGES/ocitysmap.po"
for l in languages:
print " * %s" % l
subprocess.check_call(['msgmerge', '-U',
'locale/%s/LC_MESSAGES/ocitysmap.po' % l,
'locale/ocitysmap.pot'])
return
def compile_mo(languages):
print "Compile locale/*/LC_MESSAGES/ocitysmap.mo files"
for l in languages:
print " * %s" % l
subprocess.check_call(['msgfmt', '-o',
'locale/%s/LC_MESSAGES/ocitysmap.mo' %l,
'locale/%s/LC_MESSAGES/ocitysmap.po' %l])
return
def create_language(country_code):
print "Create directory for %s" % country_code
os.makedirs('locale/%s/LC_MESSAGES' % country_code)
shutil.copyfile('locale/ocitysmap.pot',
'locale/%s/LC_MESSAGES/ocitysmap.po' % country_code)
return
def get_languages():
l = os.listdir('locale')
return filter(lambda s: s!='ocitysmap.pot', l)
def main():
usage = '%prog [options]\n WARNING: This program should be called from ocitysmap/ directory!'
parser = optparse.OptionParser(usage=usage)
parser.add_option('-P', '--make-pot', dest='make_pot',
action='store_true', default=False,
help="make locale/ocitysmap.pot")
parser.add_option('-p', '--make-po', dest='make_po',
action='store_true', default=False,
help="merge locale/ocitysmap.pot with locale/*/LC_MESSAGES/ocitysmap.po")
parser.add_option('-m', '--compile-mo', dest='compile_mo',
action='store_true', default=False,
help="compile locale/*/LC_MESSAGES/ocitysmap.mo files")
parser.add_option('-n', '--new-language', dest='new_language',
metavar='LANGUAGE_CODE',
help='create .pot file for a new language. '
'LANGUAGE_CODE is like "fr_FR".',
default=None)
(options, args) = parser.parse_args()
if len(args):
parser.print_help()
return 1
languages = get_languages()
if options.make_pot:
make_pot()
if options.make_po:
make_po(languages)
if options.compile_mo:
compile_mo(languages)
if options.new_language:
create_language(options.new_language)
if __name__ == '__main__':
sys.exit(main())