[Checkins] SVN: grok/branches/ulif-i18n/src/grok/ Move register_translations function to util.py. Get rid of i18n.py.

Uli Fouquet uli at gnufix.de
Thu Oct 18 07:48:41 EDT 2007


Log message for revision 80916:
  Move register_translations function to util.py. Get rid of i18n.py.

Changed:
  D   grok/branches/ulif-i18n/src/grok/i18n.py
  U   grok/branches/ulif-i18n/src/grok/meta.py
  U   grok/branches/ulif-i18n/src/grok/util.py

-=-
Deleted: grok/branches/ulif-i18n/src/grok/i18n.py
===================================================================
--- grok/branches/ulif-i18n/src/grok/i18n.py	2007-10-18 11:37:43 UTC (rev 80915)
+++ grok/branches/ulif-i18n/src/grok/i18n.py	2007-10-18 11:48:41 UTC (rev 80916)
@@ -1,64 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-"""I18n support for grok.
-
-You can find a (more or less) complete i18n-example in ftests.i18n.
-"""
-
-import os
-import grok
-
-from zope.component import provideUtility
-from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
-from zope.i18n.testmessagecatalog import TestMessageCatalog
-from zope.i18n.translationdomain import TranslationDomain
-from zope.i18n.interfaces import ITranslationDomain
-
-
-def registerTranslationsDirectory(directory):
-    """A replacement for the ZCML registerTranslations directive.
-
-    Basically, this is the same code as in zope.i18n.zcml, but it
-    calls ``provideUtility()`` directly.
-    """
-    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):
-            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]
-                    if not domain in domains:
-                        domains[domain] = {}
-                    domains[domain][language] = domain_path
-
-    # Now create TranslationDomain objects and add them as utilities
-    for name, langs in domains.items():
-        domain = TranslationDomain(name)
-
-        for lang, file in langs.items():
-            domain.addCatalog(GettextMessageCatalog(lang, name, file))
-
-        # make sure we have a TEST catalog for each domain:
-        domain.addCatalog(TestMessageCatalog(name))
-        # TODO: We might do some permissions checking before.
-        provideUtility(domain, ITranslationDomain, name)
-    return
-

Modified: grok/branches/ulif-i18n/src/grok/meta.py
===================================================================
--- grok/branches/ulif-i18n/src/grok/meta.py	2007-10-18 11:37:43 UTC (rev 80915)
+++ grok/branches/ulif-i18n/src/grok/meta.py	2007-10-18 11:48:41 UTC (rev 80916)
@@ -46,8 +46,8 @@
 
 import grok
 from grok import components, formlib
-from grok.util import check_adapts, get_default_permission, make_checker
-from grok.i18n import registerTranslationsDirectory
+from grok.util import (check_adapts, get_default_permission, make_checker,
+                       register_translations_directory)
 
 
 class AdapterGrokker(martian.ClassGrokker):
@@ -669,7 +669,7 @@
                         "locales directory does not exist." % (
                         localesdir, module_info.dotted_name),
                         None)
-            grok.i18n.registerTranslationsDirectory(abs_path)
+            register_translations_directory(abs_path)
         return True
 
 

Modified: grok/branches/ulif-i18n/src/grok/util.py
===================================================================
--- grok/branches/ulif-i18n/src/grok/util.py	2007-10-18 11:37:43 UTC (rev 80915)
+++ grok/branches/ulif-i18n/src/grok/util.py	2007-10-18 11:48:41 UTC (rev 80916)
@@ -13,7 +13,7 @@
 ##############################################################################
 """Grok utility functions.
 """
-
+import os
 import urllib
 
 import zope.location.location
@@ -24,6 +24,11 @@
 from zope.security.checker import NamesChecker, defineChecker
 from zope.security.interfaces import IPermission
 
+from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
+from zope.i18n.testmessagecatalog import TestMessageCatalog
+from zope.i18n.translationdomain import TranslationDomain
+from zope.i18n.interfaces import ITranslationDomain
+
 from martian.error import GrokError, GrokImportError
 from martian.util import class_annotation
 
@@ -97,3 +102,40 @@
         return obj
     # This either sets __parent__ or wraps 'obj' in a LocationProxy
     return zope.location.location.located(obj, parent, name)
+
+def register_translations_directory(directory):
+    """A replacement for the ZCML registerTranslations directive.
+
+    Basically, this is the same code as in zope.i18n.zcml, but it
+    calls ``provideUtility()`` directly.
+    """
+    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):
+            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]
+                    if not domain in domains:
+                        domains[domain] = {}
+                    domains[domain][language] = domain_path
+
+    # Now create TranslationDomain objects and add them as utilities
+    for name, langs in domains.items():
+        domain = TranslationDomain(name)
+
+        for lang, file in langs.items():
+            domain.addCatalog(GettextMessageCatalog(lang, name, file))
+
+        # make sure we have a TEST catalog for each domain:
+        domain.addCatalog(TestMessageCatalog(name))
+        # TODO: We might do some permissions checking before.
+        component.provideUtility(domain, ITranslationDomain, name)
+    return
+



More information about the Checkins mailing list