[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Maposmatic-dev] [PATCH ocitysmap] New i18n.py script to handle I18N tas
From: |
David MENTRE |
Subject: |
[Maposmatic-dev] [PATCH ocitysmap] New i18n.py script to handle I18N tasks |
Date: |
Wed, 20 Jan 2010 20:05:12 +0100 |
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".
---
i18n.py | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 103 insertions(+), 0 deletions(-)
create mode 100755 i18n.py
diff --git a/i18n.py b/i18n.py
new file mode 100755
index 0000000..ac2e8d0
--- /dev/null
+++ b/i18n.py
@@ -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())
--
1.6.0.4
- [Maposmatic-dev] [PATCH ocitysmap] New i18n.py script to handle I18N tasks,
David MENTRE <=