/usr/lib/python2.7/dist-packages/pyramid_jinja2/i18n.py is in python-pyramid-jinja2 2.7+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | from pyramid import i18n
from pyramid.threadlocal import get_current_request
class GetTextWrapper(object):
"""Implements `gettext` and `ngettext` functions for
:meth:`jinja2.Environment.install_gettext_translations`
"""
def __init__(self, domain):
self.domain = domain
@property
def localizer(self):
request = get_current_request()
try:
return request.localizer
except AttributeError: # pragma: nocover (pyramid < 1.5)
return i18n.get_localizer(request)
def gettext(self, message):
"""Implements jinja.ext.i18n `gettext` function"""
return self.localizer.translate(message,
domain=self.domain)
def ngettext(self, singular, plural, n):
"""Implements jinja.ext.i18n `ngettext` function"""
return self.localizer.pluralize(singular, plural, n,
domain=self.domain)
|