[Zope3-checkins] CVS: Zope3/utilities - i18nmergeall.py:1.1

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Apr 9 08:11:22 EDT 2004


Update of /cvs-repository/Zope3/utilities
In directory cvs.zope.org:/tmp/cvs-serv19796/utilities

Added Files:
	i18nmergeall.py 
Log Message:


Merge POT files of all available domains with PO files of all existing
languages in a given 'locales' directory. Use '-l' to specify this directory.




=== Added File Zope3/utilities/i18nmergeall.py ===
#! /usr/bin/env python2.3
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Merge a POT file with all languages

This utility requires the GNU gettext package to be installed. The command
'msgmerge' will be executed for each language.

Usage: i18mergeall.py [options]
Options:

    -h / --help
        Print this message and exit.

    -l / --locales-dir
        Specify the 'locales' directory for which to generate the statistics.

$Id: i18nmergeall.py,v 1.1 2004/04/09 12:11:22 srichter Exp $
"""
import sys
import os
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 main(path):
    for language in os.listdir(path):
        lc_messages_path = os.path.join(path, language, 'LC_MESSAGES')

        # English is the default for Zope, so ignore it
        if language == 'en':
            continue

        # Make sure we got a language directory
        if not os.path.isdir(lc_messages_path):
            continue

        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))


if __name__ == '__main__':
    try:
        opts, args = getopt.getopt(
            sys.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.')
    main(path)




More information about the Zope3-Checkins mailing list