[Checkins] SVN: z3c.pt/trunk/ Added optional support for using
zope.i18n 3.5's new negotiate function. If you use the
`zope_i18n_allowed_languages` environment variable the target
language for a template is only negotiated once per template,
instead of once for each translate function call. This more than
doubles the speed and the benchmark is back at 9.2 times faster.
Hanno Schlichting
plone at hannosch.info
Sun Jul 6 18:03:41 EDT 2008
Log message for revision 88078:
Added optional support for using zope.i18n 3.5's new negotiate function. If you use the `zope_i18n_allowed_languages` environment variable the target language for a template is only negotiated once per template, instead of once for each translate function call. This more than doubles the speed and the benchmark is back at 9.2 times faster.
Changed:
U z3c.pt/trunk/CHANGES.txt
U z3c.pt/trunk/src/z3c/pt/generation.py
-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt 2008-07-06 21:12:36 UTC (rev 88077)
+++ z3c.pt/trunk/CHANGES.txt 2008-07-06 22:03:40 UTC (rev 88078)
@@ -4,6 +4,12 @@
Version 0.8.x
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+- Added optional support for using zope.i18n 3.5's new negotiate function.
+ If you use the `zope_i18n_allowed_languages` environment variable the target
+ language for a template is only negotiated once per template, instead of
+ once for each translate function call. This more than doubles the speed
+ and the benchmark is back at 9.2 times faster.
+
- Extended the i18n handling to respect the passed in translation context to
the template. Usually this is the request, which is passed on under the
internal name of `_context` into the render functions. After extending the
Modified: z3c.pt/trunk/src/z3c/pt/generation.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/generation.py 2008-07-06 21:12:36 UTC (rev 88077)
+++ z3c.pt/trunk/src/z3c/pt/generation.py 2008-07-06 22:03:40 UTC (rev 88078)
@@ -14,17 +14,27 @@
\t(_out, _write) = generation.initialize_stream()
\t(_attributes, repeat) = generation.initialize_tal()
-\t(_domain, _translate) = generation.initialize_i18n()
+\t(_domain, _negotiate, _translate) = generation.initialize_i18n()
\t(_escape, _marker) = generation.initialize_helpers()
\t_path = generation.initialize_traversal()
-\t_target_language = target_language
+\t_target_language = _negotiate(_context, target_language)
%s
\treturn _out.getvalue()
"""
+negotiate = getattr(zope.i18n, 'negotiate', None)
+if negotiate is None:
+ def _negotiate(context, target_language):
+ return target_language
+else:
+ def _negotiate(context, target_language):
+ if target_language is not None:
+ return target_language
+ return negotiate(context)
+
def initialize_i18n():
- return (None, zope.i18n.translate)
+ return (None, _negotiate, zope.i18n.translate)
def initialize_tal():
return ({}, utils.repeatdict())
More information about the Checkins
mailing list