d0265cebaf
Rewrote the launcher in python with much improved language handling; renamed it to rungramps.py, and replaced launcher.sh with a minimal shell launcher. Any english selection will now have $LANG set to "C", while $LC_ALL will be set to whatever english variant the user selected (and en_US if she specified just "en"). For languages other than English, $LC_ALL will be set to xx_XX if the language selection had no region (e.g., if the language selection is de, $LANG will be de and $LC_ALL will be de_DE. $LANG will be truncated if the language selection has a region that Gramps doesn't support, but does support the bare language (e.g., if the language selection is de_DE, $LANG will be de because there is no de_DE translation. Gettext is smart enough to get this right without the help, but the check is necessary to ensure that we don't skip over a supported generic language. The language settings can now be overridden for gramps by using the defaults system. svn: r17342
136 lines
4.8 KiB
Python
Executable File
136 lines
4.8 KiB
Python
Executable File
#!/usr/bin/env python
|
|
import sys, os, subprocess
|
|
|
|
_home = os.environ["HOME"]
|
|
_res_path = os.path.normpath(os.path.join(sys.path[0], "..", "Resources"))
|
|
_lib_path = os.path.join(_res_path, "lib")
|
|
_share_path = os.path.join(_res_path, "share")
|
|
_pylib_path = os.path.join(_lib_path, "python2.6")
|
|
_site_lib_path = os.path.join(_pylib_path, "site-packages")
|
|
_gramps_path = os.path.join(_share_path, "gramps")
|
|
_gramps_locale = os.path.join(_share_path, "locale")
|
|
_conf_path = os.path.join(_res_path, "etc");
|
|
_gtk2_conf = os.path.join(_conf_path, "gtk-2.0")
|
|
sys.path = [_gramps_path,
|
|
os.path.join(_pylib_path, "lib-dynload"),
|
|
os.path.join(_site_lib_path, "pygtk", "2.0"),
|
|
os.path.join(_site_lib_path, "gtk-2.0"),
|
|
_site_lib_path,
|
|
_pylib_path]
|
|
|
|
os.environ["GTK_PATH"] = _res_path
|
|
os.environ["GTK2_RC_FILES"] = os.path.join(_gtk2_conf, "gtkrc")
|
|
os.environ["GTK_IM_MODULE_FILE"]= os.path.join(_gtk2_conf, "immodules")
|
|
os.environ["GDK_PIXBUF_LOADERS"] = os.path.join(_gtk2_conf, "gdk-pixbuf.loaders")
|
|
os.environ["PANGO_RC_FILES"] = os.path.join(_conf_path, "pango", "pangorc")
|
|
|
|
os.environ["GRAMPSDIR"] = _gramps_path
|
|
os.environ["GRAMPSI18N"] = _gramps_locale
|
|
os.environ["GRAMPSHOME"] = os.path.join(_home, "Library", "Application Support")
|
|
|
|
LANG = "C" #Default
|
|
defaults = "/usr/bin/defaults"
|
|
_languages = ""
|
|
_collation = ""
|
|
_locale = ""
|
|
_language = ""
|
|
try:
|
|
_languages = subprocess.Popen(
|
|
[defaults, "read", "-app", "Gramps", "AppleLanguages"],
|
|
stderr=open("/dev/null"),
|
|
stdout=subprocess.PIPE).communicate()[0].strip("()\n").split(",\n")
|
|
except:
|
|
pass
|
|
if not _languages:
|
|
try:
|
|
_languages = subprocess.Popen(
|
|
[defaults, "read", "-g", "AppleLanguages"],
|
|
stderr=open("/dev/null"),
|
|
stdout=subprocess.PIPE).communicate()[0].strip("()\n").split(",\n")
|
|
except:
|
|
pass
|
|
|
|
for _lang in _languages:
|
|
_lang=_lang.strip().strip('"').replace("-", "_", 1)
|
|
if _lang == "cn_Hant": #Traditional; Gettext uses cn_TW
|
|
_lang = "cn_TW"
|
|
if _lang == "cn_Hans": #Simplified; Gettext uses cn_CN
|
|
_lang = "cn_CN"
|
|
_language = _lang
|
|
if _lang.startswith("en"): #Gramps doesn't have explicit English translation, use C
|
|
break
|
|
if os.path.exists(os.path.join(_gramps_locale, _lang, "LC_MESSAGES",
|
|
"gramps.mo")):
|
|
LANG = _lang
|
|
break
|
|
elif os.path.exists(os.path.join(_gramps_locale, _lang[:2], "LC_MESSAGES",
|
|
"gramps.mo")):
|
|
LANG = _lang[:2]
|
|
break
|
|
try:
|
|
_collation=subprocess.Popen(
|
|
[defaults, "read", "-app", "Gramps", "AppleCollationOrder"],
|
|
stderr=open("/dev/null"),
|
|
stdout=subprocess.PIPE).communicate()[0]
|
|
except:
|
|
pass
|
|
if not _collation:
|
|
try:
|
|
_collation=subprocess.Popen(
|
|
[defaults, "read", "-g", "AppleCollationOrder"],
|
|
stderr=open("/dev/null"),
|
|
stdout=subprocess.PIPE).communicate()[0]
|
|
except:
|
|
pass
|
|
if _collation:
|
|
if LANG == "C" and not _language and os.path.exists(os.path.join(_gramps_locale, _collation,
|
|
"LC_MESSAGES", "gramps.mo")):
|
|
LANG = _collation
|
|
LC_COLLATE = _collation
|
|
if LANG == "C" and not _language:
|
|
try:
|
|
_locale=subprocess.Popen(
|
|
[defaults, "read", "-app", "Gramps", "AppleLocale"],
|
|
stderr=open("/dev/null"),
|
|
stdout=subprocess.PIPE).communicate()[0]
|
|
except:
|
|
pass
|
|
if not _locale:
|
|
try:
|
|
_locale=subprocess.Popen(
|
|
[defaults, "read", "-g", "AppleLocale"],
|
|
stderr=open("/dev/null"),
|
|
stdout=subprocess.PIPE).communicate()[0]
|
|
except:
|
|
pass
|
|
if _locale:
|
|
if os.path.exists(os.path.join(_gramps_locale, _locale[:5],
|
|
"LC_MESSAGES", "gramps.mo")):
|
|
LANG = _locale[:5]
|
|
elif os.path.exists(os.path.join(_gramps_locale, _locale[:2],
|
|
"LC_MESSAGES", "gramps.mo")):
|
|
LANG = _locale[:2]
|
|
|
|
os.environ["LANG"] = LANG
|
|
if not _language:
|
|
_language = LANG
|
|
if LC_COLLATE:
|
|
os.environ["LC_COLLATE"] = LC_COLLATE
|
|
if _language == "C" or _language == "en":
|
|
LC_ALL = "en_US"
|
|
elif len(_language) == 2:
|
|
LC_ALL = _language + "_" + _language.upper() #Because setlocale gets cranky
|
|
#if it only has two letters
|
|
else:
|
|
LC_ALL = _language
|
|
|
|
os.environ["LC_ALL"] = LC_ALL #Spell-checker dictionary support
|
|
print LANG, LC_ALL
|
|
#LaunchServices sticks this argument on the front of argument
|
|
#lists. It must make sense to somebody, but Gramps isn't that
|
|
#somebody.
|
|
for _arg in sys.argv:
|
|
if _arg.startswith("-psn"):
|
|
sys.argv.remove(_arg)
|
|
import gramps
|