From 017482b0404da670054ff1af7daf0287ddf5c532 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 15 Jun 2023 16:16:28 +0200 Subject: [PATCH] Fixing search for localistaion file --- lib/pp_admintools/xlate.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) 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() -- 2.39.5