New i18n.py script to handle I18N tasks

The set of languages is deduced from locale/ directory content.

Usage: i18n.py [options]
 WARNING: This program should be called from ocitysmap/ directory!

Options:
  -h, --help            show this help message and exit
  -P, --make-pot        make locale/ocitysmap.pot
  -p, --make-po         merge locale/ocitysmap.pot with
                        locale/*/LC_MESSAGES/ocitysmap.po
  -m, --compile-mo      compile locale/*/LC_MESSAGES/ocitysmap.mo files
  -n LANGUAGE_CODE, --new-language=LANGUAGE_CODE
                        create .pot file for a new language. LANGUAGE_CODE is
                        like "fr_FR".
stable
David MENTRE 2010-01-20 20:05:12 +01:00 zatwierdzone przez Maxime Petazzoni
rodzic 39e93aff75
commit aed528b7d6
1 zmienionych plików z 103 dodań i 0 usunięć

103
i18n.py 100755
Wyświetl plik

@ -0,0 +1,103 @@
#! /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(['pygettext', '-o', 'ocitysmap.pot', '-p', 'locale',
'ocitysmap/street_index.py',
'ocitysmap/draw_utils.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())