[Grok-dev] Request for review: grok.localesdir

Uli Fouquet uli at gnufix.de
Thu Oct 18 08:42:43 EDT 2007


Hi there,

the ulif-i18n branch is ready for review. It introduces a new directive
for registering translations in locales directories on startup. I would
be really glad, if someone could have a look at the code. It's not much
stuff and I'll assist as good as I can.

>From the reference:

   grok.localesdir(directory)
   --------------------------

   A module-level directive, which can be used to register
   a locales directory. It is a Python based equivalent to the ZCML
   directive ``i18n:registerTranslations``.

   If no value is given, the default `locales` is taken.

   The directory must exist in the path given relative to the package
   wherein the directive was used.

   The directive takes exactly one parameter and can be used several
   times per module.

   A :class:`GlobalGrokker` is called for every module in a grokked
   package. If a module does not provide a :func:`grok.localesdir`
   directive, then ``locales`` is assumed as default value and tried
   to be registered.

   This means especially, that if you do no explicit call to
   :func:`grok.localesdir`, but a local directory with name
   ``locales`` and translations exists, then this directory will be
   registered automatically.

   You can avoid this behaviour by declaring a different locales
   directory in every module of your package(s) which also might be
   empty.

   The following example registers a local ``locales`` directory as a
   source for translations (if it exists)::

      import grok

   If this code resides in a location ``/foo/bar.py``, then Zope will
   look for translations in ``/foo/locales``, but will not complain,
   if the directory does not exist or does not contain
   translations. The example is a short form for the following::

      import grok
      grok.localesdir('locales')

   whith the difference, that in this case a missing ``locales``
   directory will lead to a failure message on startup.

   You can, given that the given directories exist, declare several
   locales-directories, which will all be registered::

      import grok
      grok.localesdir('savannah')
      grok.localesdir('landofoz')

   In this case, a directory called ``locales`` will not be searched
   for translations, but ``savannah`` and ``landofoz``.   

Thanks in advance and kind regards,

-- 
Uli




More information about the Grok-dev mailing list