GrampsLocale: Get the language code from the global translation

Instead of probing locale.getlocale() and environment variables

svn: r21151
This commit is contained in:
John Ralls 2013-01-17 19:48:24 +00:00
parent df46941e73
commit e920cbfac1
4 changed files with 16 additions and 67 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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=''):
"""

View File

@ -8531,15 +8531,15 @@ def first_letter(string):
else:
letter = cuni(' ')
# See : http://www.gramps-project.org/bugs/view.php?id = 2933
(lang_country, modifier ) = locale.getlocale()
if lang_country == "sv_SE" and (letter == cuni('W') or letter == cuni('V')):
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 (lang_country == "cs_CZ" or lang_country == "sk_SK") and letter == cuni('C') and len(string) > 1:
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 lang_country == "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')
@ -8594,7 +8594,7 @@ def alphabet_navigation(menu_set):
#
# See : http://www.gramps-project.org/bugs/view.php?id = 2933
#
(lang_country, modifier) = locale.getlocale()
lang_country = glocale.get_translation().language()
for menu_item in menu_set:
sorted_set[menu_item] += 1
@ -8621,7 +8621,7 @@ def alphabet_navigation(menu_set):
while (cols <= num_of_cols and index < num_ltrs):
menu_item = sorted_alpha_index[index]
if lang_country == "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