[Checkins] SVN: z3c.recipe.i18n/trunk/ - improve i18nmergeall script
Roger Ineichen
roger at projekt01.ch
Tue Mar 10 01:15:23 EDT 2009
Log message for revision 97782:
- improve i18nmergeall script
- added i18ncompile script
- update tests
- version bump
Changed:
U z3c.recipe.i18n/trunk/CHANGES.txt
U z3c.recipe.i18n/trunk/setup.py
U z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/README.txt
U z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18n.py
A z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18ncompile.py
U z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18nmergeall.py
-=-
Modified: z3c.recipe.i18n/trunk/CHANGES.txt
===================================================================
--- z3c.recipe.i18n/trunk/CHANGES.txt 2009-03-10 03:48:48 UTC (rev 97781)
+++ z3c.recipe.i18n/trunk/CHANGES.txt 2009-03-10 05:15:22 UTC (rev 97782)
@@ -2,12 +2,15 @@
CHANGES
=======
-Version 0.5.2dev (unreleased)
------------------------------
+Version 0.5.2 (2009-03-10)
+--------------------------
-- ...
+- Feature: Generate *.po file based on *.pot file if non exists in i18nmerge
+ script
+- Feature: Implemented i18ncompile script which uses msgfmt -o moPath poPath
+
Version 0.5.1 (2009-02-22)
--------------------------
Modified: z3c.recipe.i18n/trunk/setup.py
===================================================================
--- z3c.recipe.i18n/trunk/setup.py 2009-03-10 03:48:48 UTC (rev 97781)
+++ z3c.recipe.i18n/trunk/setup.py 2009-03-10 05:15:22 UTC (rev 97782)
@@ -26,7 +26,7 @@
setup(
name = 'z3c.recipe.i18n',
- version = '0.5.2dev',
+ version = '0.5.2',
author = 'Roger Ineichen and the Zope Community',
author_email = 'zope-dev at zope.org',
description = 'Zope3 egg based i18n locales extration recipes',
Modified: z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/README.txt
===================================================================
--- z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/README.txt 2009-03-10 03:48:48 UTC (rev 97781)
+++ z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/README.txt 2009-03-10 05:15:22 UTC (rev 97782)
@@ -115,12 +115,15 @@
Generated script '/sample-buildout/bin/i18nextract'.
Generated script '/sample-buildout/bin/i18nmergeall'.
Generated script '/sample-buildout/bin/i18nstats'.
+ Generated script '/sample-buildout/bin/i18ncompile'.
After running buildout, the bin folder contains the different i18n script::
>>> ls('bin')
- buildout-script.py
- buildout.exe
+ - i18ncompile-script.py
+ - i18ncompile.exe
- i18nextract-script.py
- i18nextract.exe
- i18nmergeall-script.py
@@ -188,6 +191,25 @@
z3c.recipe.i18n.i18nstats.main(['i18nstats', '-l', '...outputDir'])
+i18ncompile
+-----------
+
+The i18ncompile.py contains the following code::
+
+ >>> cat('bin', 'i18ncompile-script.py')
+ #!C:\Python24\python.exe
+ <BLANKLINE>
+ import sys
+ sys.path[0:0] = [
+ ...
+ ]
+ <BLANKLINE>
+ import z3c.recipe.i18n.i18ncompile
+ <BLANKLINE>
+ if __name__ == '__main__':
+ z3c.recipe.i18n.i18ncompile.main(['i18ncompile', '-l', '...outputDir'])
+
+
Full Sample
-----------
@@ -226,12 +248,15 @@
Generated script '/sample-buildout/bin/i18nextract'.
Generated script '/sample-buildout/bin/i18nmergeall'.
Generated script '/sample-buildout/bin/i18nstats'.
+ Generated script '/sample-buildout/bin/i18ncompile'.
After running buildout, the bin folder contains the different i18n script::
>>> ls('bin')
- buildout-script.py
- buildout.exe
+ - i18ncompile-script.py
+ - i18ncompile.exe
- i18nextract-script.py
- i18nextract.exe
- i18nmergeall-script.py
Modified: z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18n.py
===================================================================
--- z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18n.py 2009-03-10 03:48:48 UTC (rev 97781)
+++ z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18n.py 2009-03-10 05:15:22 UTC (rev 97782)
@@ -167,6 +167,19 @@
arguments = arguments,
))
+ # Generate i18ncompile
+ arguments = ['%scompile'% self.name, '-l', output]
+ generated.extend(
+ zc.buildout.easy_install.scripts(
+ [('%scompile'% self.name,
+ 'z3c.recipe.i18n.i18ncompile',
+ 'main')],
+ ws, self.options['executable'],
+ self.buildout['buildout']['bin-directory'],
+ extra_paths = [this_loc],
+ arguments = arguments,
+ ))
+
return generated
update = install
Added: z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18ncompile.py
===================================================================
--- z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18ncompile.py (rev 0)
+++ z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18ncompile.py 2009-03-10 05:15:22 UTC (rev 97782)
@@ -0,0 +1,88 @@
+#!/usr/bin/env python2.4
+##############################################################################
+#
+# Copyright (c) 2008 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.
+#
+##############################################################################
+"""Compile PO files to Mo files for all languages in a given locales dir
+
+This utility requires the GNU gettext package to be installed. The command
+'msgfmt' will be executed for each language.
+
+Usage: i18ncompile.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 os.path
+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 msgfmt(path):
+ for language in os.listdir(path):
+ lc_messages_path = os.path.join(path, language, 'LC_MESSAGES')
+
+ # Make sure we got a language directory
+ if not os.path.isdir(lc_messages_path):
+ continue
+
+ for poFile in os.listdir(lc_messages_path):
+ if poFile.endswith('.po'):
+ domain = poFile.split('.')[0]
+ base = os.path.join(lc_messages_path, domain)
+ poPath = str(base + '.po')
+ moPath = str(base + '.mo')
+ print 'Compile language "%s" for "%s"' % (language, domain)
+ os.system('msgfmt -o %s %s' %(moPath, poPath))
+
+
+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.')
+ msgfmt(path)
+
+if __name__ == '__main__':
+ main()
+
Modified: z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18nmergeall.py
===================================================================
--- z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18nmergeall.py 2009-03-10 03:48:48 UTC (rev 97781)
+++ z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18nmergeall.py 2009-03-10 05:15:22 UTC (rev 97782)
@@ -17,7 +17,7 @@
This utility requires the GNU gettext package to be installed. The command
'msgmerge' will be executed for each language.
-Usage: i18mergeall.py [options]
+Usage: i18nmergeall.py [options]
Options:
-h / --help
@@ -41,6 +41,12 @@
def merge(path):
+ for pot_name in os.listdir(path):
+ if pot_name.endswith('.pot'):
+ break
+ domain = pot_name.split('.')[0]
+ potPath = os.path.join(path, domain+'.pot')
+
for language in os.listdir(path):
lc_messages_path = os.path.join(path, language, 'LC_MESSAGES')
@@ -48,14 +54,15 @@
if not os.path.isdir(lc_messages_path):
continue
+ poPath = os.path.join(lc_messages_path, domain+'.po')
+ if not os.path.exists(poPath):
+ poFile = open(poPath, 'wb')
+ poFile.write(open(potPath, 'rb').read())
+ poFile.close()
+
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 -U %s %s' %(domain_path, pot_path))
+ print 'Merging language "%s", domain "%s"' %(language, domain)
+ os.system('msgmerge -U %s %s' %(poPath, potPath))
def main(argv=sys.argv):
More information about the Checkins
mailing list