Skip to content

Commit

Permalink
Adding non-setuptools check
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Dec 25, 2017
1 parent 9f73a29 commit 7a87f9f
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions plumbum/cli/i18n.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
import os
import gettext
import pkg_resources

# If not installed with setuptools, this might not be available
try:
import pkg_resources
except ImportError:
pkg_resources = None

try:
from typing import Tuple, List, Callable
except ImportError:
pass

local_dir = os.path.basename(__file__)

def get_translation_for(package_name): # type: (str) -> gettext.NullTranslations
'find and return gettext translation for package'
'''Find and return gettext translation for package
(Try to find folder manually if setuptools does not exist)
'''

if '.' in package_name:
package_name = '.'.join(package_name.split('.')[:-1])
localedir = None
for localedir in pkg_resources.resource_filename(package_name, 'i18n'), None:

if pkg_resources is None:
mydir = os.path.join(local_dir, 'i18n')
else:
mydir = pkg_resources.resource_filename(package_name, 'i18n')

for localedir in mydir, None:
localefile = gettext.find(package_name, localedir)
if localefile:
break
else:
pass

return gettext.translation(package_name, localedir=localedir, fallback=True)


Expand Down

0 comments on commit 7a87f9f

Please sign in to comment.