[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
|
__first_instance = None
|
||||||
encoding = None
|
encoding = None
|
||||||
|
_lang_map = None
|
||||||
|
_country_map = None
|
||||||
|
|
||||||
def __new__(cls, localedir=None, lang=None, domain=None, languages=None):
|
def __new__(cls, localedir=None, lang=None, domain=None, languages=None):
|
||||||
if not GrampsLocale.__first_instance:
|
if not GrampsLocale.__first_instance:
|
||||||
@ -490,6 +492,9 @@ class GrampsLocale(object):
|
|||||||
|
|
||||||
self.translation = self._get_translation(self.localedomain,
|
self.translation = self._get_translation(self.localedomain,
|
||||||
self.localedir, self.language)
|
self.localedir, self.language)
|
||||||
|
self._set_dictionaries()
|
||||||
|
|
||||||
|
|
||||||
if _hdlr:
|
if _hdlr:
|
||||||
LOG.removeHandler(_hdlr)
|
LOG.removeHandler(_hdlr)
|
||||||
|
|
||||||
@ -533,51 +538,54 @@ class GrampsLocale(object):
|
|||||||
def _set_dictionaries(self):
|
def _set_dictionaries(self):
|
||||||
"""
|
"""
|
||||||
Create a dictionary of language names localized to the
|
Create a dictionary of language names localized to the
|
||||||
GrampsLocale's primary language, keyed by language and
|
GrampsLocale's primary language, keyed by language and country
|
||||||
country code.
|
code. Note that _lang_map and _country_map are class
|
||||||
|
variables, so this function is no-op in secondary locales.
|
||||||
"""
|
"""
|
||||||
_ = self.translation.gettext
|
_ = self.translation.gettext
|
||||||
self.lang_map = {
|
if not self._lang_map:
|
||||||
"bg" : _("Bulgarian"),
|
self._lang_map = {
|
||||||
"ca" : _("Catalan"),
|
"bg" : _("Bulgarian"),
|
||||||
"cs" : _("Czech"),
|
"ca" : _("Catalan"),
|
||||||
"da" : _("Danish"),
|
"cs" : _("Czech"),
|
||||||
"de" : _("German"),
|
"da" : _("Danish"),
|
||||||
"el" : _("Greek"),
|
"de" : _("German"),
|
||||||
"en" : _("English"),
|
"el" : _("Greek"),
|
||||||
"eo" : _("Esperanto"),
|
"en" : _("English"),
|
||||||
"es" : _("Spanish"),
|
"eo" : _("Esperanto"),
|
||||||
"fi" : _("Finnish"),
|
"es" : _("Spanish"),
|
||||||
"fr" : _("French"),
|
"fi" : _("Finnish"),
|
||||||
"he" : _("Hebrew"),
|
"fr" : _("French"),
|
||||||
"hr" : _("Croatian"),
|
"he" : _("Hebrew"),
|
||||||
"hu" : _("Hungarian"),
|
"hr" : _("Croatian"),
|
||||||
"it" : _("Italian"),
|
"hu" : _("Hungarian"),
|
||||||
"ja" : _("Japanese"),
|
"it" : _("Italian"),
|
||||||
"lt" : _("Lithuanian"),
|
"ja" : _("Japanese"),
|
||||||
"mk" : _("Macedonian"),
|
"lt" : _("Lithuanian"),
|
||||||
"nb" : _("Norwegian Bokmal"),
|
"mk" : _("Macedonian"),
|
||||||
"nl" : _("Dutch"),
|
"nb" : _("Norwegian Bokmal"),
|
||||||
"nn" : _("Norwegian Nynorsk"),
|
"nl" : _("Dutch"),
|
||||||
"pl" : _("Polish"),
|
"nn" : _("Norwegian Nynorsk"),
|
||||||
"pt" : _("Portuguese"),
|
"pl" : _("Polish"),
|
||||||
"ro" : _("Romanian"),
|
"pt" : _("Portuguese"),
|
||||||
"ru" : _("Russian"),
|
"ro" : _("Romanian"),
|
||||||
"sk" : _("Slovak"),
|
"ru" : _("Russian"),
|
||||||
"sl" : _("Slovenian"),
|
"sk" : _("Slovak"),
|
||||||
"sq" : _("Albanian"),
|
"sl" : _("Slovenian"),
|
||||||
"sv" : _("Swedish"),
|
"sq" : _("Albanian"),
|
||||||
"tr" : _("Turkish"),
|
"sv" : _("Swedish"),
|
||||||
"uk" : _("Ukrainian"),
|
"tr" : _("Turkish"),
|
||||||
"vi" : _("Vietnamese"),
|
"uk" : _("Ukrainian"),
|
||||||
"zh" : _("Chinese")
|
"vi" : _("Vietnamese"),
|
||||||
|
"zh" : _("Chinese")
|
||||||
}
|
}
|
||||||
|
|
||||||
self.country_map = {
|
if not self._country_map:
|
||||||
"BR" : _("Brazil"),
|
self._country_map = {
|
||||||
"CN" : _("China"),
|
"BR" : _("Brazil"),
|
||||||
"PT" : _("Portugal")
|
"CN" : _("China"),
|
||||||
}
|
"PT" : _("Portugal")
|
||||||
|
}
|
||||||
|
|
||||||
def _get_language_string(self, lang_code):
|
def _get_language_string(self, lang_code):
|
||||||
"""
|
"""
|
||||||
@ -587,17 +595,15 @@ class GrampsLocale(object):
|
|||||||
code_parts = lang_code.rsplit("_")
|
code_parts = lang_code.rsplit("_")
|
||||||
|
|
||||||
lang = code_parts[0]
|
lang = code_parts[0]
|
||||||
if not hasattr(self, 'lang_map'):
|
|
||||||
self._set_dictionaries()
|
|
||||||
|
|
||||||
if lang in self.lang_map:
|
if lang in self._lang_map:
|
||||||
lang = self.lang_map[lang]
|
lang = self._lang_map[lang]
|
||||||
|
|
||||||
country = None
|
country = None
|
||||||
if len(code_parts) > 1:
|
if len(code_parts) > 1:
|
||||||
country = code_parts[1]
|
country = code_parts[1]
|
||||||
if country in self.country_map:
|
if country in self._country_map:
|
||||||
country = self.country_map[country]
|
country = self._country_map[country]
|
||||||
lang = "%(language)s (%(country)s)" % \
|
lang = "%(language)s (%(country)s)" % \
|
||||||
{ 'language' : lang, 'country' : country }
|
{ 'language' : lang, 'country' : country }
|
||||||
|
|
||||||
@ -697,14 +703,15 @@ class GrampsLocale(object):
|
|||||||
"""
|
"""
|
||||||
languages = ["en"]
|
languages = ["en"]
|
||||||
|
|
||||||
if not localedir and hasattr(self, 'localedir'):
|
if not localedir and self.localedir:
|
||||||
localedir = self.localedir
|
localedir = self.localedir
|
||||||
|
else:
|
||||||
if localedir is None:
|
|
||||||
return languages
|
return languages
|
||||||
|
|
||||||
if not localedomain and hasattr(self, 'localedomain'):
|
if not localedomain and self.localedomain:
|
||||||
localedomain = self.localedomain
|
localedomain = self.localedomain
|
||||||
|
else:
|
||||||
|
localedomain = 'gramps'
|
||||||
|
|
||||||
for langdir in os.listdir(self.localedir):
|
for langdir in os.listdir(self.localedir):
|
||||||
mofilename = os.path.join(localedir, langdir,
|
mofilename = os.path.join(localedir, langdir,
|
||||||
|
Loading…
Reference in New Issue
Block a user