[Zope-Coders] ZPT Translation Service

Florent Guillaume fg@nuxeo.com
Thu, 19 Sep 2002 16:48:21 +0000 (UTC)


> http://dev.zope.org/Wikis/DevSite/Proposals/GlobalZPTTranslationServiceHook

I think I'll update the translation service signature to:

    def translate(domain, msgid, mapping=None,
                  context=None, target_language=None,
                  here=None, request=None)

because translation services that wish to provide placeful behavior have
to be able to get at 'here' (remember that this translation service is
aimed a ZPT, it's not completely generic), and to provide intelligent
language negociation they need to get 'request'.

In this scenario I don't overload the meaning of 'context', which was
defined in Zope 3 to have to implement IUserPreferredLanguages. But
maybe it can be used for 'here'? What were the plans for 'context' in
Zope 2?

An alternative to the first scenario would be to keep the original
signature, but use here=context and request=context.REQUEST (but the
latter is probably a bit slower than getting 'request' from TALES's
expression engine).

Then in TALES.py I'll do something like:

    def translate(self, domain, msgid, mapping=None,
                  context=None, target_language=None):
        getcontext = self.contexts.get
        return getGlobalTranslationService().translate(
            domain, msgid, mapping=mapping,
            context=context, target_language=target_language,
            here=getcontext('here'), request=getcontext('request'))

Or, using the alternative scenario:

    def translate(self, domain, msgid, mapping=None,
                  context=None, target_language=None):
        if context is None:
            context = self.contexts.get('here')
        return getGlobalTranslationService().translate(
            domain, msgid, mapping=mapping,
            context=context, target_language=target_language)

Comments?

Florent
-- 
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87  http://nuxeo.com  mailto:fg@nuxeo.com