def get_i18n(factory=I18n, key=_i18n_registry_key, request=None):
"""Returns an instance of :class:`I18n` from the request registry.
It'll try to get it from the current request registry, and if it is not
registered it'll be instantiated and registered. A second call to this
function will return the same instance.
:param factory:
The callable used to build and register the instance if it is not yet
registered. The default is the class :class:`I18n` itself.
:param key:
The key used to store the instance in the registry. A default is used
if it is not set.
:param request:
A :class:`webapp2.Request` instance used to store the instance. The
active request is used if it is not set.
"""
request = request or webapp2.get_request()
i18n = request.registry.get(key)
if not i18n:
i18n = request.registry[key] = factory(request)
return i18n
评论列表
文章目录