[r21962]GrampsLocale: Make dictionaries class variables
lang_map and country_map svn: r21979
This commit is contained in:
parent
044452805b
commit
9f1ec6daf6
@ -145,6 +145,8 @@ class GrampsLocale(object):
|
||||
"""
|
||||
__first_instance = None
|
||||
encoding = None
|
||||
_lang_map = None
|
||||
_country_map = None
|
||||
|
||||
def __new__(cls, localedir=None, lang=None, domain=None, languages=None):
|
||||
if not GrampsLocale.__first_instance:
|
||||
@ -490,6 +492,9 @@ class GrampsLocale(object):
|
||||
|
||||
self.translation = self._get_translation(self.localedomain,
|
||||
self.localedir, self.language)
|
||||
self._set_dictionaries()
|
||||
|
||||
|
||||
if _hdlr:
|
||||
LOG.removeHandler(_hdlr)
|
||||
|
||||
@ -533,11 +538,13 @@ class GrampsLocale(object):
|
||||
def _set_dictionaries(self):
|
||||
"""
|
||||
Create a dictionary of language names localized to the
|
||||
GrampsLocale's primary language, keyed by language and
|
||||
country code.
|
||||
GrampsLocale's primary language, keyed by language and country
|
||||
code. Note that _lang_map and _country_map are class
|
||||
variables, so this function is no-op in secondary locales.
|
||||
"""
|
||||
_ = self.translation.gettext
|
||||
self.lang_map = {
|
||||
if not self._lang_map:
|
||||
self._lang_map = {
|
||||
"bg" : _("Bulgarian"),
|
||||
"ca" : _("Catalan"),
|
||||
"cs" : _("Czech"),
|
||||
@ -573,7 +580,8 @@ class GrampsLocale(object):
|
||||
"zh" : _("Chinese")
|
||||
}
|
||||
|
||||
self.country_map = {
|
||||
if not self._country_map:
|
||||
self._country_map = {
|
||||
"BR" : _("Brazil"),
|
||||
"CN" : _("China"),
|
||||
"PT" : _("Portugal")
|
||||
@ -587,17 +595,15 @@ class GrampsLocale(object):
|
||||
code_parts = lang_code.rsplit("_")
|
||||
|
||||
lang = code_parts[0]
|
||||
if not hasattr(self, 'lang_map'):
|
||||
self._set_dictionaries()
|
||||
|
||||
if lang in self.lang_map:
|
||||
lang = self.lang_map[lang]
|
||||
if lang in self._lang_map:
|
||||
lang = self._lang_map[lang]
|
||||
|
||||
country = None
|
||||
if len(code_parts) > 1:
|
||||
country = code_parts[1]
|
||||
if country in self.country_map:
|
||||
country = self.country_map[country]
|
||||
if country in self._country_map:
|
||||
country = self._country_map[country]
|
||||
lang = "%(language)s (%(country)s)" % \
|
||||
{ 'language' : lang, 'country' : country }
|
||||
|
||||
@ -697,14 +703,15 @@ class GrampsLocale(object):
|
||||
"""
|
||||
languages = ["en"]
|
||||
|
||||
if not localedir and hasattr(self, 'localedir'):
|
||||
if not localedir and self.localedir:
|
||||
localedir = self.localedir
|
||||
|
||||
if localedir is None:
|
||||
else:
|
||||
return languages
|
||||
|
||||
if not localedomain and hasattr(self, 'localedomain'):
|
||||
if not localedomain and self.localedomain:
|
||||
localedomain = self.localedomain
|
||||
else:
|
||||
localedomain = 'gramps'
|
||||
|
||||
for langdir in os.listdir(self.localedir):
|
||||
mofilename = os.path.join(localedir, langdir,
|
||||
|
Loading…
Reference in New Issue
Block a user