[Zope] Re: Hmm... Localizer or Localizer

Peter Bengtsson peter at fry-it.com
Tue Sep 5 14:16:50 EDT 2006


On 9/5/06, Philipp von Weitershausen <philipp at weitershausen.de> wrote:
> Peter Bengtsson wrote:
> > But how do you use it? I installed Five 1.2.6
> > In my product's directory I created a configure.zcml that looks like this::
> > <configure xmlns="http://namespaces.zope.org/zope"
> >           xmlns:browser="http://namespaces.zope.org/browser"
> >           xmlns:i18n="http://namespaces.zope.org/i18n"
> >           package="Products.RememberYourFriends">
> >
> >  <i18n:registerTranslations directory="i18n" />
> >
> > </configure>
> >
> > Starts without errors. My ryf-sv.po file isn't automatically compiled
> > to .mo
>
> Right. The Zope 3 machinery doesn't do that. Use msgfmt from the gettext
> utilities to compile catalogs.
>
> You're also using PTS's non-standard directory layout. The standard
> gettext layout is somedir/LC_MESSAGES/<lang>/<domain>.mo. PTS supports
> this as well but Plone continues not to go standard here and set a bad
> example :(
>
Seems awefully academic to me but if that's the standard, let's do it.
I now have a file called:
locales/LC_MESSAGES/sv/ryf.mo

> > and I tried changing the HTTP_ACCEPT_LANGUAGE variable but
> > still just the old default English.
>
> HTTP_ACCEPT_LANGUAGE isn't a variable. It's an HTTP header
> (Accept-Language) that you really shouldn't modify. The request should
> be treated as read-only.
>
> To test languages, either write your own IUserPreferredLanguages adapter
> that returns the language you want or simply configure your browser to
> send a different Accept-Language header. In Firefox, you can simply do
> this by entering "about:config" in the URL bar and changing the setting
> of the intl.accept_languages variable (e.g. to "se, en").
>
> > Either I've missed something big and crucial or there's a bug in lack
> > of errors or alerts.
>
> You simply didn't read Five/doc/i18n.txt
> (http://codespeak.net/z3/five/i18n.html). Googling "five i18n" gives you
> that as a first hit. "RTFM" is all I can say here.
>
Don't RTFM me! I've read that page and unless you have a PhD in
physics and indept experience of Zope 3 is really doesn't make a lot
of sense. Plus, I've got your cookbook at home :)

So, should I use PTS or not??
"The default behaviour for choosing languages in Five is the one of
Zope 3: analyze the Accept-Language HTTP header and nothing more."
This is not good enough. When I send out email alerts to people in my
app, that's a wget script that kicks if off, not a Mozilla browser.
Besides, what if an Englishman is using a Swedish
internetcafe-computer when on holiday; in that case I want to allow
him to manually configure his user profile on my site.

I have no idea what this does or what I'm supposed to do with:
<adapter
    for="zope.publisher.interfaces.http.IHTTPRequest"
    provides="zope.i18n.interfaces.IUserPreferredLanguages"
    factory="Products.Five.i18n.PTSLanguages"
    />

Please tell me there's a function or something that works like this::

  def index_html(self):
       uid = self._getLoggedinUID()
       wants_lang = self._getUserPreference(uid, default='en')
       setCurrentLanguage(wants_lang)
       return _("I wish it was easier")

 def manage_setUserPreference(self, uid, lang):
      if lang in getAvailableLanguages():
          self._setUserPreference(uid, lang)

Where _getUserPreference() and _setUserPreference() is something I'm
expected to write for my app.

-- 
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com


More information about the Zope mailing list