1# -*- coding: utf-8 -*- 2import gettext 3import locale 4import os 5import six 6 7 8''' 9.. py:attribute:: LOCALE_PATH 10 11 Path on the file system to the locale/ directory, used to find translations 12 for the current locale. 13 14 15.. py:attribute:: CONVENTION 16 17 Container for all the locale conventions, see 18 http://docs.python.org/library/locale.html#locale.localeconv 19''' 20 21 22locale.setlocale(locale.LC_ALL, '') 23 24LOCALE_PATH = os.path.join(os.path.dirname(__file__), 'locale') 25gettext.bindtextdomain('natural', LOCALE_PATH) 26gettext.textdomain('natural') 27try: 28 TRANSLATION = gettext.translation('natural', LOCALE_PATH) 29 if six.PY2: 30 _ = TRANSLATION.ugettext 31 else: 32 _ = TRANSLATION.gettext 33except IOError: 34 if six.PY2: 35 _ = gettext.NullTranslations().ugettext 36 else: 37 _ = gettext.NullTranslations().gettext 38 39# generic 40CONVENTION = locale.localeconv() 41 42 43def _multi(singular, plural, count): 44 ''' 45 Provides translations for plural and singular forms of a term. 46 ''' 47 if count == 1: 48 return singular 49 else: 50 return plural 51