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

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:13:54 -0500


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

Added Files:
	__init__.py configure.zcml meta.zcml metaconfigure.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/app/i18n/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:54 2002
+++ Zope3/src/zope/app/i18n/__init__.py	Wed Dec 25 09:12:53 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/i18n/configure.zcml 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:54 2002
+++ Zope3/src/zope/app/i18n/configure.zcml	Wed Dec 25 09:12:53 2002
@@ -0,0 +1,30 @@
+<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>


=== Zope3/src/zope/app/i18n/meta.zcml 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:54 2002
+++ Zope3/src/zope/app/i18n/meta.zcml	Wed Dec 25 09:12:53 2002
@@ -0,0 +1,14 @@
+<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>


=== Zope3/src/zope/app/i18n/metaconfigure.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:54 2002
+++ Zope3/src/zope/app/i18n/metaconfigure.py	Wed Dec 25 09:12:53 2002
@@ -0,0 +1,53 @@
+##############################################################################
+#
+# 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$
+"""
+
+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,))]