From 98898ddb7153a931cb543873d287a37b2eb5c84c Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sun, 24 Feb 2013 00:52:59 +0000 Subject: [PATCH] [r21151]GrampsLocale: Get the language code from the global translation Instead of probing locale.getlocale() and environment variables svn: r21399 --- gramps/gen/relationship.py | 40 ++---------------------- gramps/gen/utils/grampslocale.py | 2 +- gramps/gui/display.py | 29 ++++------------- gramps/plugins/webreport/narrativeweb.py | 14 +++++---- 4 files changed, 18 insertions(+), 67 deletions(-) diff --git a/gramps/gen/relationship.py b/gramps/gen/relationship.py index c6d344d64..c0b746510 100644 --- a/gramps/gen/relationship.py +++ b/gramps/gen/relationship.py @@ -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() diff --git a/gramps/gen/utils/grampslocale.py b/gramps/gen/utils/grampslocale.py index 77c5b48c8..eaa631bab 100644 --- a/gramps/gen/utils/grampslocale.py +++ b/gramps/gen/utils/grampslocale.py @@ -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) diff --git a/gramps/gui/display.py b/gramps/gui/display.py index 401f2f724..f4ae0e964 100644 --- a/gramps/gui/display.py +++ b/gramps/gui/display.py @@ -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 - 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 +lang = glocale.get_translation().language() +if lang in MANUALS: + EXTENSION = MANUALS[lang] +else: + EXTENSION = '' def display_help(webpage='', section=''): """ diff --git a/gramps/plugins/webreport/narrativeweb.py b/gramps/plugins/webreport/narrativeweb.py index deb3de96d..bc0980588 100644 --- a/gramps/plugins/webreport/narrativeweb.py +++ b/gramps/plugins/webreport/narrativeweb.py @@ -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