[r21640]GrampsLocale: Reduce circular imports
Lets one import grampslocale directly in a test script: >>> from gramps.gen.utils.grampslocale import GrampsLocale >>> import os >>> gl = GrampsLocale(lang='fr_FR.UTF-8', localedir=os.path.join('build', 'mo')) >>> tr = gl.get_translation().gettext >>> tr("List of known family trees in your database path\n") u'Liste des arbres familiaux connus dans votre chemin de base de donn\xe9es\n' svn: r21647
This commit is contained in:
parent
0fda971b4c
commit
2629bf3dee
@ -80,17 +80,6 @@ APP_GRAMPS_PKG = "application/x-gramps-package"
|
||||
APP_GENEWEB = "application/x-geneweb"
|
||||
APP_VCARD = ["text/x-vcard", "text/x-vcalendar"]
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Platforms
|
||||
# Never test on LINUX, handle Linux in the else statement as default
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
LINUX = ["Linux", "linux", "linux2"]
|
||||
MACOS = ["Darwin", "darwin"]
|
||||
WINDOWS = ["Windows", "win32"]
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Determine the home directory. According to Wikipedia, most UNIX like
|
||||
@ -176,7 +165,7 @@ WEBSTUFF_IMAGE_DIR = os.path.join(WEBSTUFF_DIR, "images")
|
||||
|
||||
USE_TIPS = False
|
||||
|
||||
if os.sys.platform in WINDOWS:
|
||||
if sys.platform == 'win32':
|
||||
USE_THUMBNAILER = False
|
||||
else:
|
||||
USE_THUMBNAILER = True
|
||||
@ -188,7 +177,6 @@ else:
|
||||
#-------------------------------------------------------------------------
|
||||
from gramps.gen.utils.resourcepath import ResourcePath
|
||||
_resources = ResourcePath()
|
||||
LOCALE_DIR = _resources.locale_dir
|
||||
DATA_DIR = _resources.data_dir
|
||||
IMAGE_DIR = _resources.image_dir
|
||||
|
||||
@ -206,7 +194,7 @@ LICENSE_FILE = os.path.join(_resources.doc_dir, 'COPYING')
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gramps.gen.utils.grampslocale import GrampsLocale
|
||||
GRAMPS_LOCALE = GrampsLocale()
|
||||
GRAMPS_LOCALE = GrampsLocale(localedir=_resources.locale_dir)
|
||||
_ = GRAMPS_LOCALE.get_translation().sgettext
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
@ -37,10 +37,13 @@ import sys
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Gramps modules
|
||||
# Platforms
|
||||
# Never test on LINUX, handle Linux in the else statement as default
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from .const import WINDOWS, MACOS, LINUX
|
||||
LINUX = ["Linux", "linux", "linux2"]
|
||||
MACOS = ["Darwin", "darwin"]
|
||||
WINDOWS = ["Windows", "win32"]
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
|
@ -50,7 +50,6 @@ except ImportError:
|
||||
# gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ..const import LOCALE_DIR
|
||||
from ..constfunc import mac, win, UNITYPE
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
@ -159,7 +158,7 @@ class GrampsLocale(object):
|
||||
LOG.warning("Localization library libintl not on %PATH%, localization will be incomplete")
|
||||
|
||||
|
||||
def __init_first_instance(self, localedir=None, lang=None,
|
||||
def __init_first_instance(self, localedir, lang=None,
|
||||
domain=None, language=None):
|
||||
|
||||
#First, globally set the locale to what's in the environment:
|
||||
@ -170,21 +169,13 @@ class GrampsLocale(object):
|
||||
|
||||
if localedir and os.path.exists(localedir):
|
||||
self.localedir = localedir
|
||||
else:
|
||||
if ("GRAMPSI18N" in os.environ
|
||||
and os.path.exists(os.environ["GRAMPSI18N"])):
|
||||
self.localedir = os.environ["GRAMPSI18N"]
|
||||
elif os.path.exists(LOCALE_DIR):
|
||||
self.localedir = LOCALE_DIR
|
||||
elif os.path.exists(os.path.join(sys.prefix, "share", "locale")):
|
||||
self.localedir = os.path.join(sys.prefix, "share", "locale")
|
||||
else:
|
||||
if not lang:
|
||||
lang = os.environ.get('LANG', 'en')
|
||||
if lang and lang[:2] == 'en':
|
||||
pass # No need to display warning, we're in English
|
||||
else:
|
||||
LOG.warning('Locale dir does not exist at %s', LOCALE_DIR)
|
||||
LOG.warning('Locale dir does not exist at %s', localedir)
|
||||
LOG.warning('Running python setup.py install --prefix=YourPrefixDir might fix the problem')
|
||||
|
||||
if not self.localedir:
|
||||
@ -248,7 +239,7 @@ class GrampsLocale(object):
|
||||
self.initialized = True
|
||||
|
||||
|
||||
def __init__(self, lang=None, localedir=None, domain=None, languages=None):
|
||||
def __init__(self, localedir=None, lang=None, domain=None, languages=None):
|
||||
"""
|
||||
Init a GrampsLocale. Run __init_first_instance() to set up the
|
||||
environement if this is the first run. Return __first_instance
|
||||
@ -256,7 +247,7 @@ class GrampsLocale(object):
|
||||
"""
|
||||
if self == self._GrampsLocale__first_instance:
|
||||
if not self.initialized:
|
||||
self._GrampsLocale__init_first_instance(lang, localedir,
|
||||
self._GrampsLocale__init_first_instance(localedir, lang,
|
||||
domain, languages)
|
||||
else:
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user