[Zope3-checkins] CVS: Zope3/src/zope/app/i18n - meta.zcml:1.4 metaconfigure.py:1.4 metadirectives.py:1.3

Stephan Richter srichter at cosmos.phy.tufts.edu
Mon Mar 8 18:36:57 EST 2004


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

Modified Files:
	meta.zcml metaconfigure.py metadirectives.py 
Log Message:


Adjusted code to the new API. Also renamed 'gts' namespace to 'i18n'. I wanted
to do this for a very long time.


=== Zope3/src/zope/app/i18n/meta.zcml 1.3 => 1.4 ===
--- Zope3/src/zope/app/i18n/meta.zcml:1.3	Sun Aug  3 16:58:38 2003
+++ Zope3/src/zope/app/i18n/meta.zcml	Mon Mar  8 18:36:26 2004
@@ -1,20 +1,14 @@
 <configure
-    xmlns='http://namespaces.zope.org/zope'
+    xmlns="http://namespaces.zope.org/zope"
     xmlns:meta="http://namespaces.zope.org/meta"
     >
 
-  <meta:directives namespace="http://namespaces.zope.org/gts">
+  <meta:directives namespace="http://namespaces.zope.org/i18n">
 
     <meta:directive
         name="registerTranslations"
         schema=".metadirectives.IRegisterTranslationsDirective"
         handler=".metaconfigure.registerTranslations"
-        />
-
-    <meta:directive
-        name="defaultLanguages"
-        schema=".metadirectives.IDefaultLanguagesDirective"
-        handler=".metaconfigure.defaultLanguages"
         />
 
   </meta:directives>


=== Zope3/src/zope/app/i18n/metaconfigure.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/i18n/metaconfigure.py:1.3	Sun Aug  3 16:58:38 2003
+++ Zope3/src/zope/app/i18n/metaconfigure.py	Mon Mar  8 18:36:26 2004
@@ -11,19 +11,23 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""
-This module handles the :startup directives.
+"""This module handles the 'i18n' namespace directives.
 
 $Id$
 """
-
 import os
+from zope.app.component.metaconfigure import utility
 from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
-from zope.i18n.globaltranslationservice import translationService
+from zope.i18n.translationdomain import TranslationDomain
+from zope.i18n.interfaces import ITranslationDomain
 
 def registerTranslations(_context, directory):
     path = os.path.normpath(directory)
+    domains = {}
 
+    # Gettext has the domain-specific catalogs inside the language directory,
+    # which is exactly the opposite as we need it. So create a dictionary that
+    # reverses the nesting. 
     for language in os.listdir(path):
         lc_messages_path = os.path.join(path, language, 'LC_MESSAGES')
         if os.path.isdir(lc_messages_path):
@@ -31,18 +35,14 @@
                 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)
-
-                    _context.action(
-                        discriminator = catalog.getIdentifier(),
-                        callable = translationService.addCatalog,
-                        args = (catalog,)
-                        )
-
-def defaultLanguages(_context, languages):
-    return _context.action(
-        discriminator = ('gts', tuple(languages)),
-        callable = translationService.setLanguageFallbacks,
-        args = (languages,)
-        )
+                    if not domain in domains:
+                        domains[domain] = {}
+                    domains[domain][language] = domain_path
+
+    # Now create TranslationDomain objects and add them as utitlities
+    for name, langs in domains.items():
+        domain = TranslationDomain(name)
+        for lang, file in langs.items():
+            domain.addCatalog(GettextMessageCatalog(lang, name, file))
+        utility(_context, ITranslationDomain, domain, name=name)
+                              


=== Zope3/src/zope/app/i18n/metadirectives.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/i18n/metadirectives.py:1.2	Sun Aug 17 02:06:42 2003
+++ Zope3/src/zope/app/i18n/metadirectives.py	Mon Mar  8 18:36:26 2004
@@ -14,10 +14,8 @@
 """
 $Id$
 """
-
 from zope.interface import Interface
-from zope.configuration.fields import Tokens, Path
-from zope.schema import TextLine
+from zope.configuration.fields import Path
 
 class IRegisterTranslationsDirective(Interface):
 
@@ -25,13 +23,4 @@
         title=u"Directory",
         description=u"Directory containing the translations",
         required=True
-        )
-
-class IDefaultLanguagesDirective(Interface):
-
-    languages = Tokens(
-        title=u"Languages",
-        description=u"Use these as default languages",
-        required=True,
-        value_type=TextLine()
         )




More information about the Zope3-Checkins mailing list