[Zope3-dev] Re: Zope 2.9 and Zope 3 i18n, more questions...
Philipp von Weitershausen
philipp at weitershausen.de
Tue Jun 6 07:53:07 EDT 2006
Chris Withers wrote:
> Philipp von Weitershausen wrote:
>> You would inherit from the default implementation in
>> zope.publisher.browser.BrowserLanguages and override
>> getPreferredLanguages. Inside I presume you would get the current user
>> in the Zope 2 manner, getSecurityManager().getUser(), and do your
>> checks. If that won't lead to anything, you can simply return
>> super(...).getPreferredLanguages() to default to browser languages.
>
> Cool, thanks. Once I've developed this component, how do I plug it in
> zcml-wise?
It's an adapter for IHTTPRequest (or IBrowserRequest), so you'd use
<adapter />.
>>> from Products.PageTemplates.GlobalTranslationService import \
>>> getGlobalTranslationService
>>> ts = getGlobalTranslationService()
>>> ts.translate(domain,
>>> msgid,
>>> context=self,
>>> target_language=target_language,
>>> default=default)
>>>
>>> What's the equivalent in Z3 land or should I be looking to turn all
>>> calls to the above into MessageID's? If I do, when and how do they get
>>> translated?
>>
>> 1) We usually don't do manual translation in Python
>
> What about sending notification mails and the like?
That's where we do use it. I said *usually*, didn't I? ;).
>> 2) Instead we mark all user strings ("messages") as i18n messages (using
>> zope.i18nmessageid.MessageFactory). That also helps the automatic
>> extraction utility to find them.
>
> Okay, but what translates these and when?
As I said, the ZPT engine does that automatically when it encounters a
Message object.
>> 4) In case you *do* need manual translation in Python (sometimes it
>> happens), you can call zope.i18n.translate(msgid, context=REQUEST)
>> (notice the context is the request here).
>
> Is msgid a string or a MessageID object there?
msgid is a Message object (MessageID in Zope 2.8).
>>> I've made calls to the following too:
>>>
>>> name = ts.getLanguageName('en',self) #'en' is just an example
>>>
>>> current = ts.negotiate_language(self,domain) or default
>>>
>>> languages = [{'code':code,
>>> 'name':ts.getLanguageName(code, self),
>>> 'selected':current==code} for code in
>>> ts.getLanguages(self,domain)]
>>>
>>> What are the new-world equivalents of these?
>>
>> Why would you need this?
>
> For UI. Showing language names in the UI and showing a list of available
> languages to let the user pick their own. How would would build these in
> Zope 3? (and, more importantly, in 2.9 with Five?)
See Hanno's replies...
Philipp
More information about the Zope3-dev
mailing list