[r21151]GrampsLocale: Get the language code from the global translation
Instead of probing locale.getlocale() and environment variables svn: r21399
This commit is contained in:
parent
8cbba85cf1
commit
98898ddb71
@ -1792,49 +1792,15 @@ def get_relationship_calculator(reinit=False):
|
||||
global __RELCALC_CLASS
|
||||
|
||||
if __RELCALC_CLASS is None or reinit:
|
||||
lang = ' '
|
||||
try:
|
||||
lang = os.environ["LANG"]
|
||||
lang_set = True
|
||||
except:
|
||||
# if LANG is not set
|
||||
import locale
|
||||
lang = locale.getlocale()[0]
|
||||
if not lang:
|
||||
# if lang is empty/None
|
||||
lang = locale.getdefaultlocale()[0]
|
||||
lang_set = False
|
||||
lang = glocale.get_translation().language()
|
||||
__RELCALC_CLASS = RelationshipCalculator
|
||||
# If lang not set default to English relationship calulator
|
||||
if not lang:
|
||||
return __RELCALC_CLASS()
|
||||
# See if lang begins with en_, English_ or english_
|
||||
# If so return standard relationship calculator.
|
||||
enlang = lang.split('_')[0].lower()
|
||||
if enlang in ('en', 'english', 'c'):
|
||||
if lang == "en":
|
||||
return __RELCALC_CLASS()
|
||||
# set correct non English relationship calculator based on LANG
|
||||
# or on locale.getlocale() or if that fails locale.getdeafultlocale()
|
||||
# set correct non English relationship calculator based on lang
|
||||
relation_translation_found = False
|
||||
for plugin in PluginRegister.get_instance().relcalc_plugins():
|
||||
if lang in plugin.lang_list:
|
||||
pmgr = BasePluginManager.get_instance()
|
||||
# the loaded module is put in variable mod
|
||||
mod = pmgr.load_plugin(plugin)
|
||||
if mod:
|
||||
__RELCALC_CLASS = eval('mod.' + plugin.relcalcclass)
|
||||
relation_translation_found = True
|
||||
break
|
||||
if not relation_translation_found:
|
||||
# LANG set but with non recognizable language info. Try getlocale
|
||||
import locale
|
||||
lang = locale.getlocale()[0]
|
||||
if not lang:
|
||||
# if lang is empty/None
|
||||
try:
|
||||
lang = locale.getdefaultlocale()[0]
|
||||
except:
|
||||
pass
|
||||
for plugin in PluginRegister.get_instance().relcalc_plugins():
|
||||
if lang in plugin.lang_list:
|
||||
pmgr = BasePluginManager.get_instance()
|
||||
|
@ -423,7 +423,7 @@ class GrampsNullTranslations(gettext.NullTranslations):
|
||||
Note that it's necessary for msgid to be unicode. If it's not,
|
||||
neither will be the returned string.
|
||||
"""
|
||||
def sgettext(self, msgid):
|
||||
def sgettext(self, msgid, sep='|'):
|
||||
msgval = self.gettext(msgid)
|
||||
if msgval == msgid:
|
||||
sep_idx = msgid.rfind(sep)
|
||||
|
@ -23,7 +23,7 @@
|
||||
from gramps.gen.const import URL_MANUAL_PAGE, URL_WIKISTRING
|
||||
from gramps.gen.constfunc import is_quartz
|
||||
from gramps.gen.config import config
|
||||
import locale
|
||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||
import os
|
||||
|
||||
#list of manuals on wiki, map locale code to wiki extension, add language codes
|
||||
@ -40,28 +40,11 @@ MANUALS = {
|
||||
}
|
||||
|
||||
#first, determine language code, so nl_BE --> wiki /nl
|
||||
LANG = locale.getlocale()[0]
|
||||
if not LANG:
|
||||
LANG = 'C'
|
||||
#support environment overrule:
|
||||
try:
|
||||
if not os.environ['LANGUAGE'] or \
|
||||
os.environ['LANGUAGE'].split(':')[0] == LANG:
|
||||
pass
|
||||
lang = glocale.get_translation().language()
|
||||
if lang in MANUALS:
|
||||
EXTENSION = MANUALS[lang]
|
||||
else:
|
||||
LANG = os.environ['LANGUAGE'].split(':')[0]
|
||||
except:
|
||||
pass
|
||||
EXTENSION = ''
|
||||
try:
|
||||
EXTENSION = MANUALS[LANG]
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
if not EXTENSION :
|
||||
EXTENSION = MANUALS[LANG.split('_')[0]]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
def display_help(webpage='', section=''):
|
||||
"""
|
||||
|
@ -8534,14 +8534,15 @@ def first_letter(string):
|
||||
else:
|
||||
letter = cuni(' ')
|
||||
# See : http://www.gramps-project.org/bugs/view.php?id = 2933
|
||||
if COLLATE_LANG == "sv_SE" and (letter == cuni('W') or letter == cuni('V')):
|
||||
letter = cuni('V,W')
|
||||
lang_country = glocale.get_translation().language()
|
||||
if lang_country == "sv" and (letter == cuni('W') or letter == cuni('V')):
|
||||
letter = 'V,W'
|
||||
# See : http://www.gramps-project.org/bugs/view.php?id = 4423
|
||||
elif (COLLATE_LANG == "cs_CZ" or COLLATE_LANG == "sk_SK") and letter == cuni('C') and len(string) > 1:
|
||||
second_letter = normalize('NFKC', cuni(string))[1].upper()
|
||||
elif (lang_country == "cs" or lang_country == "sk") and letter == cuni('C') and len(string) > 1:
|
||||
second_letter = normalize('NFKC', str(string))[1].upper()
|
||||
if second_letter == cuni('H'):
|
||||
letter += cuni('h')
|
||||
elif COLLATE_LANG == "sk_SK" and letter == cuni('D') and len(string) > 1:
|
||||
elif lang_country == "sk" and letter == cuni('D') and len(string) > 1:
|
||||
second_letter = normalize('NFKC', cuni(string))[1].upper()
|
||||
if second_letter == cuni('Z'):
|
||||
letter += cuni('z')
|
||||
@ -8596,6 +8597,7 @@ def alphabet_navigation(menu_set):
|
||||
#
|
||||
# See : http://www.gramps-project.org/bugs/view.php?id = 2933
|
||||
#
|
||||
lang_country = glocale.get_translation().language()
|
||||
|
||||
for menu_item in menu_set:
|
||||
sorted_set[menu_item] += 1
|
||||
@ -8622,7 +8624,7 @@ def alphabet_navigation(menu_set):
|
||||
while (cols <= num_of_cols and index < num_ltrs):
|
||||
menu_item = sorted_alpha_index[index]
|
||||
|
||||
if COLLATE_LANG == "sv_SE" and menu_item == cuni('V'):
|
||||
if lang_country == "sv" and menu_item == cuni('V'):
|
||||
hyper = Html("a", "V,W", href = "#V,W", title = "V,W")
|
||||
else:
|
||||
# adding title to hyperlink menu for screen readers and braille writers
|
||||
|
Loading…
Reference in New Issue
Block a user