[Zope3-checkins] CVS: Zope3/src/zope/app/i18n - __init__.py:1.1.2.1 configure.zcml:1.1.2.1 meta.zcml:1.1.2.1 metaconfigure.py:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:31:38 -0500


Update of /cvs-repository/Zope3/src/zope/app/i18n
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/i18n

Added Files:
      Tag: NameGeddon-branch
	__init__.py configure.zcml meta.zcml metaconfigure.py 
Log Message:
Initial renaming before debugging

=== Added File Zope3/src/zope/app/i18n/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/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="zope.interfaces.i18n.INegotiator" />

<service serviceType="LanguageNegotiation" 
    component="zope.i18n.negotiator.negotiator" />

<adapter factory="zope.publisher.browser.BrowserLanguages"
    for="zope.publisher.interfaces.browser.IBrowserRequest"
    provides="zope.interfaces.i18n.IUserPreferredLanguages" />

<!-- Setup charset negotiation -->
<adapter factory="zope.publisher.http.HTTPCharsets"
    for="zope.publisher.interfaces.http.IHTTPRequest"
    provides="zope.interfaces.i18n.IUserPreferredCharsets" />

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

<service serviceType="Translation"
    permission="Zope.Public"
    component="zope.i18n.globaltranslationservice.translationService" />

</zopeConfigure>


=== Added File Zope3/src/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="zope.app.i18n.metaconfigure.registerTranslations" />

    <directive name="defaultLanguages"
               attributes="languages"
               handler="zope.app.i18n.metaconfigure.defaultLanguages" />

  </directives>
</zopeConfigure>


=== Added File Zope3/src/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.2.1 2002/12/23 19:31:36 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,))]