[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/i18n - __init__.py:1.1 configure.zcml:1.1 meta.zcml:1.1 metaConfigure.py:1.1

Jim Fulton jim@zope.com
Wed, 18 Dec 2002 18:37:05 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/i18n
In directory cvs.zope.org:/tmp/cvs-serv25839/lib/python/Zope/App/i18n

Added Files:
	__init__.py configure.zcml meta.zcml metaConfigure.py 
Log Message:
Cleaned up after some other checkins.

- Fixed some zcml files that weren't fixed in a refactoring.
  This prevented Zope from starting.

- Renamed some modules that had invalid module names.
  Created some packages for these as well. Moved some tests around
  Fixed up file references to reflect changes.




=== Added File Zope3/lib/python/Zope/App/i18n/__init__.py ===
#


=== Added File Zope3/lib/python/Zope/App/i18n/configure.zcml ===
<zopeConfigure
   xmlns="http://namespaces.zope.org/zope"
   xmlns:service="http://namespaces.zope.org/service"
   xmlns:gts="http://namespaces.zope.org/gts"
   package="Zope.I18n"
   >

<!-- Setup language negotiation -->
<serviceType id="LanguageNegotiation" interface=".INegotiator." />

<service serviceType="LanguageNegotiation" 
    component=".Negotiator.negotiator" />

<adapter factory="Zope.Publisher.Browser.BrowserLanguages."
    for="Zope.Publisher.Browser.IBrowserRequest."
    provides="Zope.I18n.IUserPreferredLanguages." />

<!-- Setup charset negotiation -->
<adapter factory="Zope.Publisher.HTTP.HTTPCharsets."
    for="Zope.Publisher.HTTP.IHTTPRequest."
    provides="Zope.I18n.IUserPreferredCharsets." />

<!-- Setup Translation Service -->
<serviceType id="Translation" interface=".ITranslationService." />

<service serviceType="Translation"
    permission="Zope.Public"
    component=".GlobalTranslationService.translationService" />

</zopeConfigure>


=== Added File Zope3/lib/python/Zope/App/i18n/meta.zcml ===
<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
  <!-- Zope.I18n -->
  <directives namespace="http://namespaces.zope.org/gts">

    <directive name="registerTranslations"
               attributes="directory"
               handler=".metaConfigure.registerTranslations" />

    <directive name="defaultLanguages"
               attributes="languages"
               handler=".metaConfigure.defaultLanguages" />

  </directives>
</zopeConfigure>


=== Added File Zope3/lib/python/Zope/App/i18n/metaConfigure.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
# 
##############################################################################
"""
This module handles the :startup directives. 

$Id: metaConfigure.py,v 1.1 2002/12/18 23:37:03 jim Exp $
"""

import os
from Zope.Configuration.Action import Action
from Zope.I18n.GettextMessageCatalog import GettextMessageCatalog
from Zope.I18n.GlobalTranslationService import translationService

def registerTranslations(_context, directory):
    """ """
    actions = []

    path = _context.path(directory)
    path = os.path.normpath(path)

    for language in os.listdir(path):
        lc_messages_path = os.path.join(path, language, 'LC_MESSAGES')
        if os.path.isdir(lc_messages_path):
            for domain_file in os.listdir(lc_messages_path):
                if domain_file.endswith('.mo'):
                    domain_path = os.path.join(lc_messages_path, domain_file)
                    domain = domain_file[:-3]
                    catalog = GettextMessageCatalog(language, domain,
                                                    domain_path)

                    actions.append(Action(
                        discriminator = catalog.getIdentifier(),
                        callable = translationService.addCatalog,
                        args = (catalog,) ))
    return actions


def defaultLanguages(_context, languages):
    langs = [L.strip() for L in languages.split()]
    return [Action(discriminator = ('gts', languages),
                   callable = translationService.setLanguageFallbacks,
                   args = (langs,))]