From: Frank Brehm Date: Thu, 15 Jun 2023 14:16:28 +0000 (+0200) Subject: Fixing search for localistaion file X-Git-Tag: 0.10.0^2~9 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=017482b0404da670054ff1af7daf0287ddf5c532;p=pixelpark%2Fpp-admin-tools.git Fixing search for localistaion file --- diff --git a/lib/pp_admintools/xlate.py b/lib/pp_admintools/xlate.py index 066548a..d14bdc2 100644 --- a/lib/pp_admintools/xlate.py +++ b/lib/pp_admintools/xlate.py @@ -15,6 +15,7 @@ from __future__ import absolute_import, print_function import copy import gettext import logging +import sys try: from pathlib import Path except ImportError: @@ -30,17 +31,32 @@ DOMAIN = 'pp_admintools' LOG = logging.getLogger(__name__) -__version__ = '0.1.1' +__version__ = '0.2.1' __me__ = Path(__file__).resolve() __module_dir__ = __me__.parent __lib_dir__ = __module_dir__.parent __base_dir__ = __lib_dir__.parent -LOCALE_DIR = __base_dir__.joinpath('locale') -if not LOCALE_DIR.is_dir(): - LOCALE_DIR = __module_dir__.joinpath('locale') - if not LOCALE_DIR.is_dir(): - LOCALE_DIR = None +LOCALE_DIR = __base_dir__ / 'locale' +if LOCALE_DIR.is_dir(): + # Not installed, in development workdir + LOCALE_DIR = str(LOCALE_DIR) +else: + # Somehow installed + if sys.prefix == sys.base_prefix: + # installed as a package + LOCALE_DIR = sys.prefix + '/share/locale' + else: + # Obviously in a virtual environment + LOCALE_DIR = __lib_dir__ / 'usr' / 'local' / 'share' / 'locale' + if LOCALE_DIR.is_dir(): + LOCALE_DIR = str(LOCALE_DIR.resolve()) + else: + LOCALE_DIR = __module_dir__ / 'locale' + if LOCALE_DIR.is_dir(): + LOCALE_DIR = str(LOCALE_DIR) + else: + LOCALE_DIR = sys.prefix + '/share/locale' DEFAULT_LOCALE_DEF = 'en_US' DEFAULT_LOCALE = babel.core.default_locale()