Skip to content
Browse files

[svn] deprecating h.lang for the new helpers setup does not support it

--HG--
branch : trunk
  • Loading branch information...
1 parent 2013f22 commit 370437db2bb3db81677086c3d818ba7b0b6caef1 pjenvey committed Sep 3, 2006
Showing with 12 additions and 3 deletions.
  1. +1 −0 CHANGELOG
  2. +3 −3 docs/internationalization.txt
  3. +8 −0 pylons/util.py
View
1 CHANGELOG
@@ -16,6 +16,7 @@ Pylons Changelog
- Added translator global to __init__.py for use with new Helpers cleanup.
- Copied Helpers function methods directly into util so they can be used
stand-alone.
+ - Deprecated h.lang (for h.set_lang/h.get_lang)
* Moved the 'default_charset' option from PylonsApp's constructor to
Config's.
* Added 'error' controller route to the top of the Pylons template to avoid
View
6 docs/internationalization.txt
@@ -27,8 +27,8 @@ Edit ``controllers/hello.py`` controller to look like this making use of the ``_
resp = Response()
resp.write('Default: %s<br />'%h._('Hello'))
for lang in ['fr','en','es']:
- h.lang = lang
- resp.write("%s: %s<br />"%(h.lang, h._('Hello')))
+ h.set_lang(lang)
+ resp.write("%s: %s<br />"%(h.get_lang(), h._('Hello')))
return resp
The controller has now been internationalized but it won't function properly until we have specified the alternative languages.
@@ -154,7 +154,7 @@ Modify the last line of the hello controller to look like this:
.. code-block:: Python
- resp.write("%s: %s %s<br />" % (h.lang, h._('Hello'), h._('World!')))
+ resp.write("%s: %s %s<br />" % (h.get_lang(), h._('Hello'), h._('World!')))
If you run the example again the output will be::
View
8 pylons/util.py
@@ -8,6 +8,7 @@
import gettext
import os.path
import sys
+import warnings
from paste.deploy.config import CONFIG
from paste.script.templates import Template
from routes import threadinglocal
@@ -107,6 +108,10 @@ def __getattr__(self, name):
elif hasattr(pylons.request, '_h') and hasattr(pylons.request._h, name):
return getattr(pylons.request._h, name)
elif name in pylons.translator:
+ if name == 'lang':
+ warnings.warn('Getting the translator language via h.lang is '
+ 'deprecated: Please use h.get_lang() instead',
+ DeprecationWarning, 2)
return pylons.translator[name]
else:
raise AttributeError("No such helper: '%s'" % repr(name))
@@ -117,6 +122,9 @@ def __setattr__(self, name, value):
"the special 'lang' attribute. Use the "
"context object 'c' to store context data.")
else:
+ warnings.warn("Setting the translator language via h.lang = '%s' is "
+ "deprecated: Please use h.set_lang('%s') instead" % \
+ (value, value), DeprecationWarning, 2)
self.set_lang(value)
def translate(self, value):

0 comments on commit 370437d

Please sign in to comment.
Something went wrong with that request. Please try again.