New Param: Added Param.get_label() method for a way to retrieve translated message at request time

This commit is contained in:
Jason Gerard DeRose
2009-01-05 01:20:14 -07:00
parent 026860bd56
commit c121d0064b
5 changed files with 64 additions and 9 deletions

View File

@@ -23,6 +23,7 @@ Parameter system for command plugins.
from types import NoneType
from util import make_repr
from request import ugettext
from plugable import ReadOnly, lock, check_name
from constants import NULLS, TYPE_ERROR, CALLABLE_ERROR
@@ -199,6 +200,7 @@ class Param(ReadOnly):
kwargs = (
('cli_name', str, None),
('label', callable, None),
('doc', str, ''),
('required', bool, True),
('multivalue', bool, False),
@@ -301,6 +303,14 @@ class Param(ReadOnly):
**self.__kw
)
def get_label(self):
"""
Return translated label using `request.ugettext`.
"""
if self.label is None:
return self.cli_name.decode('UTF-8')
return self.label(ugettext)
def normalize(self, value):
"""
Normalize ``value`` using normalizer callback.