[Zope3-checkins] SVN: Zope3/trunk/src/zope/ Deprecated passing a(n
ignored) location argument to translate
Jim Fulton
jim at zope.com
Wed Jul 7 12:51:50 EDT 2004
Log message for revision 26164:
Deprecated passing a(n ignored) location argument to translate
This resolves an XXX.
-=-
Modified: Zope3/trunk/src/zope/app/form/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/form/__init__.py 2004-07-07 16:50:18 UTC (rev 26163)
+++ Zope3/trunk/src/zope/app/form/__init__.py 2004-07-07 16:51:50 UTC (rev 26164)
@@ -42,8 +42,7 @@
self.context.description))
def _translate(self, text):
- return translate(self.context, text, "zope",
- context=self.request, default=text)
+ return translate(text, "zope", context=self.request, default=text)
def _renderedValueSet(self):
"""Returns True if the the widget's rendered value has been set.
Modified: Zope3/trunk/src/zope/app/form/browser/itemswidgets.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/itemswidgets.py 2004-07-07 16:50:18 UTC (rev 26163)
+++ Zope3/trunk/src/zope/app/form/browser/itemswidgets.py 2004-07-07 16:51:50 UTC (rev 26164)
@@ -62,8 +62,7 @@
"""A mixin class that provides the translation capabilities."""
def translate(self, msgid):
- return translate(self.context, msgid, context=self.request,
- default=msgid)
+ return translate(msgid, context=self.request, default=msgid)
def message(msgid, default):
"""Add a default value to a i18n message id."""
Modified: Zope3/trunk/src/zope/app/form/browser/sequencewidget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/sequencewidget.py 2004-07-07 16:50:18 UTC (rev 26163)
+++ Zope3/trunk/src/zope/app/form/browser/sequencewidget.py 2004-07-07 16:51:50 UTC (rev 26164)
@@ -82,15 +82,15 @@
if render and num_items > min_length:
remove_botton_name = 'remove-selected-items-of-seq-' + self.name
button_label = _('remove-selected-items', "Remove selected items")
- button_label = translate(self.context, button_label,
- context=self.request, default=button_label)
+ button_label = translate(button_label, context=self.request,
+ default=button_label)
buttons += '<input type="submit" value="%s" name="%s"/>' % (
button_label, remove_botton_name)
if max_length is None or num_items < max_length:
field = self.context.value_type
button_label = _('Add %s')
- button_label = translate(self.context, button_label,
- context=self.request, default=button_label)
+ button_label = translate(button_label, context=self.request,
+ default=button_label)
button_label = button_label % (field.title or field.__name__)
buttons += '<input type="submit" name="%s.add" value="%s" />' % (
self.name, button_label)
Modified: Zope3/trunk/src/zope/app/pagetemplate/engine.py
===================================================================
--- Zope3/trunk/src/zope/app/pagetemplate/engine.py 2004-07-07 16:50:18 UTC (rev 26163)
+++ Zope3/trunk/src/zope/app/pagetemplate/engine.py 2004-07-07 16:51:50 UTC (rev 26164)
@@ -82,7 +82,7 @@
# When running Zope, request is a Proxy, but no mutation is done here,
# so it is safe to remove all proxies
request = removeAllProxies(self.request)
- return translate(self.context, msgid, domain, mapping,
+ return translate(msgid, domain, mapping,
context=request, default=default)
evaluateInlineCode = False
Modified: Zope3/trunk/src/zope/i18n/__init__.py
===================================================================
--- Zope3/trunk/src/zope/i18n/__init__.py 2004-07-07 16:50:18 UTC (rev 26163)
+++ Zope3/trunk/src/zope/i18n/__init__.py 2004-07-07 16:51:50 UTC (rev 26164)
@@ -16,6 +16,7 @@
$Id$
"""
import re
+import warnings
from zope.i18nmessageid import MessageIDFactory, MessageID
from zope.i18n.interfaces import ITranslationDomain
@@ -28,19 +29,17 @@
_get_var_regex = re.compile(r'%(n)s' %({'n': NAME_RE}))
-# XXX: location not needed
-def translate(location, msgid, domain=None, mapping=None, context=None,
- target_language=None, default=None):
+def _translate(msgid, domain=None, mapping=None, context=None,
+ target_language=None, default=None):
- # XXX: For some reason, I get a recursive import when placing this import
- # outside the function. I have no clue how to fix this. SR
- from zope.component import queryUtility
if isinstance(msgid, MessageID):
domain = msgid.domain
default = msgid.default
mapping = msgid.mapping
+ # XXX we shouldn't need this import here
+ from zope.component import queryUtility
util = queryUtility(ITranslationDomain, domain)
if util is None:
@@ -48,7 +47,19 @@
return util.translate(msgid, mapping, context, target_language, default)
+# BBB Backward compat
+def translate(*args, **kw):
+ if args and not isinstance(args[0], basestring):
+ warnings.warn(
+ "translate no longer takes a location argument. "
+ "The argument was ignored.",
+ DeprecationWarning, 2)
+ args = args[1:]
+ return _translate(*args, **kw)
+
+
+
def interpolate(text, mapping):
"""Insert the data passed from mapping into the text"""
More information about the Zope3-Checkins
mailing list