Skip to content

Commit

Permalink
Merge pull request #132 from eldipa/Fix81-Use-Resource-Instead-File
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Jun 27, 2020
2 parents 16fa071 + 1e4b885 commit 976ad4a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/humanize/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
_TRANSLATIONS = {None: gettext_module.NullTranslations()}
_CURRENT = local()

_DEFAULT_LOCALE_PATH = os.path.join(os.path.dirname(__file__), "locale")
try:
_DEFAULT_LOCALE_PATH = os.path.join(os.path.dirname(__file__), "locale")
except AttributeError:
# in case that __file__ does not exist
_DEFAULT_LOCALE_PATH = None


def get_translation():
Expand All @@ -23,6 +27,12 @@ def activate(locale, path=None):
@param path: path to search for locales"""
if path is None:
path = _DEFAULT_LOCALE_PATH

if path is None:
raise Exception(
"Humanize cannot determinate the default location of the 'locale' folder. "
"You need to pass the path explicitly."
)
if locale not in _TRANSLATIONS:
translation = gettext_module.translation("humanize", path, [locale])
_TRANSLATIONS[locale] = translation
Expand Down

0 comments on commit 976ad4a

Please sign in to comment.