Hello Chris,

Le 25/04/10 15:19, Chris McDonough a écrit :
> BFG 1.3 will ship with internationalization and localization
> features. [...]
> If anyone who needs these features has a chance to provide feedback
> on or otherwise help out on those docs, I'd be grateful.

I "ported" (sic) a small application (from zope.i18n). The documentation
is (as usual) very detailed and easy to read.

One thing that struck me is the default locale negotiator: it does not
look at the "Accept-Language" HTTP header. Fair enough, I'll write my
own, something like:

  def locale_negotiator(request):
      ## Use BFG default negotiator
      locale = default_locale_negotiator(request)
      if locale is not None:
          return locale

      available_languages = ['fr', 'de'] ## FIXME

      ## No cookie, nothing in the request parameters, let's look
      ## at what the browser accepts and prefers.
      accepts = request.headers.get('Accept-Language', None)
      if not accepts:
          return None
      ## The following is probably not bullet-proof but whatever...
      for part in accepts.split(','):
        lang = part.split(';')[0].strip()
        if lang in available_languages:
            return lang
        lang = lang.split('-')[0]
        if lang in available_languages:
            return lang
    return None

This is all well, but I need a list of available languages, here. As far
as I can see, translation directories are registered when the
application starts. Then localizers are registered on-demand when a
particular language is requested. May I ask what is the intent behind
this behaviour (rather than registering all localizers at startup)? It
obviously cut down startup times: is this the only reason? If all
localizers were registered at startup, I would be able to get a list of
available languages with something like:

    [l[0] for l in registry.getUtilitiesFor(ILocalizer)]

However, in the current situation, I have to 'listdir()' each
translation directory, which looks redundant with what is done in
"i18n.get_localizer()" to register ILocalizer utilities. Of course I
could do that only once, when the application gets started. But isn't
there a better way?


Damien Baty
Repoze-dev mailing list

Reply via email to