/usr/share/pyshared/humanize/i18n.py is in python-humanize 0.5-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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | # -*- coding: utf-8 -*-
import gettext as gettext_module
from threading import local
import os.path
__all__ = ['activate', 'deactivate', 'gettext', 'ngettext']
_TRANSLATIONS = {None: gettext_module.NullTranslations()}
_CURRENT = local()
_DEFAULT_LOCALE_PATH = os.path.join(os.path.dirname(__file__), 'locale')
def get_translation():
try:
return _TRANSLATIONS[_CURRENT.locale]
except (AttributeError, KeyError):
return _TRANSLATIONS[None]
def activate(locale, path=None):
"""Set 'locale' as current locale. Search for locale in directory 'path'
@param locale: language name, eg 'en_GB'"""
if path is None:
path = _DEFAULT_LOCALE_PATH
translation = gettext_module.translation('humanize', path, [locale])
_TRANSLATIONS[locale] = translation
_CURRENT.locale = locale
return translation
def deactivate():
_CURRENT.locale = None
def gettext(message):
return get_translation().gettext(message)
def ngettext(message, plural, num):
return get_translation().ngettext(message, plural, num)
def gettext_noop(message):
"""Example usage:
CONSTANTS = [gettext_noop('first'), gettext_noop('second')]
def num_name(n):
return gettext(CONSTANTS[n])"""
return message
|