[r21236]GrampsLocale: Replace use of get_language_string
... with GrampsLocale.get_language_dict Permits sorting by localized language name. Also hides the language code, which the user doesn't really care about. Removes get_language_string from libtranslate.py, no longer needed. svn: r21411
This commit is contained in:
parent
bbf16cb40c
commit
efa53a0537
@ -223,6 +223,7 @@ class GrampsLocale(object):
|
||||
|
||||
self.translation = self._get_translation(self.localedomain,
|
||||
self.localedir, self.language)
|
||||
self._set_dictionaries()
|
||||
|
||||
|
||||
|
||||
@ -251,6 +252,76 @@ class GrampsLocale(object):
|
||||
domain, languages, localedir)
|
||||
return GrampsNullTranslations()
|
||||
|
||||
def _set_dictionaries(self):
|
||||
"""
|
||||
Create a dictionary of language names localized to the
|
||||
GrampsLocale's primary language, keyed by language and
|
||||
country code.
|
||||
"""
|
||||
_ = self.translation.gettext
|
||||
self.lang_map = {
|
||||
"bg" : _("Bulgarian"),
|
||||
"ca" : _("Catalan"),
|
||||
"cs" : _("Czech"),
|
||||
"da" : _("Danish"),
|
||||
"de" : _("German"),
|
||||
"el" : _("Greek"),
|
||||
"en" : _("English"),
|
||||
"eo" : _("Esperanto"),
|
||||
"es" : _("Spanish"),
|
||||
"fi" : _("Finnish"),
|
||||
"fr" : _("French"),
|
||||
"he" : _("Hebrew"),
|
||||
"hr" : _("Croatian"),
|
||||
"hu" : _("Hungarian"),
|
||||
"it" : _("Italian"),
|
||||
"ja" : _("Japanese"),
|
||||
"lt" : _("Lithuanian"),
|
||||
"mk" : _("Macedonian"),
|
||||
"nb" : _("Norwegian Bokmal"),
|
||||
"nl" : _("Dutch"),
|
||||
"nn" : _("Norwegian Nynorsk"),
|
||||
"pl" : _("Polish"),
|
||||
"pt" : _("Portuguese"),
|
||||
"ro" : _("Romanian"),
|
||||
"ru" : _("Russian"),
|
||||
"sk" : _("Slovak"),
|
||||
"sl" : _("Slovenian"),
|
||||
"sq" : _("Albanian"),
|
||||
"sv" : _("Swedish"),
|
||||
"tr" : _("Turkish"),
|
||||
"uk" : _("Ukrainian"),
|
||||
"vi" : _("Vietnamese"),
|
||||
"zh" : _("Chinese")
|
||||
}
|
||||
|
||||
self.country_map = {
|
||||
"BR" : _("Brazil"),
|
||||
"CN" : _("China"),
|
||||
"PT" : _("Portugal")
|
||||
}
|
||||
|
||||
def _get_language_string(self, lang_code):
|
||||
"""
|
||||
Given a language code of the form "lang_region", return a text string
|
||||
representing that language.
|
||||
"""
|
||||
code_parts = lang_code.rsplit("_")
|
||||
|
||||
lang = code_parts[0]
|
||||
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]
|
||||
lang = "%(language)s (%(country)s)" % \
|
||||
{ 'language' : lang, 'country' : country }
|
||||
|
||||
return lang
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Public Functions
|
||||
@ -368,6 +439,18 @@ class GrampsLocale(object):
|
||||
|
||||
return languages
|
||||
|
||||
def get_language_dict(self):
|
||||
'''
|
||||
return a dictionary of language names : codes for use by language
|
||||
pickers.
|
||||
'''
|
||||
langs = {}
|
||||
for code in self.get_available_translations():
|
||||
langs[self._get_language_string(code)] = code
|
||||
|
||||
return langs
|
||||
|
||||
|
||||
def trans_objclass(self, objclass_str):
|
||||
"""
|
||||
Translates objclass_str into "... %s", where objclass_str
|
||||
|
@ -42,79 +42,6 @@ from gramps.gen.config import config
|
||||
from gramps.gen.lib.grampstype import GrampsType
|
||||
from gramps.gen.constfunc import cuni
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Private Constants
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
_LANG_MAP = {
|
||||
"bg" : _("Bulgarian"),
|
||||
"ca" : _("Catalan"),
|
||||
"cs" : _("Czech"),
|
||||
"da" : _("Danish"),
|
||||
"de" : _("German"),
|
||||
"el" : _("Greek"),
|
||||
"en" : _("English"),
|
||||
"eo" : _("Esperanto"),
|
||||
"es" : _("Spanish"),
|
||||
"fi" : _("Finnish"),
|
||||
"fr" : _("French"),
|
||||
"he" : _("Hebrew"),
|
||||
"hr" : _("Croatian"),
|
||||
"hu" : _("Hungarian"),
|
||||
"it" : _("Italian"),
|
||||
"ja" : _("Japanese"),
|
||||
"lt" : _("Lithuanian"),
|
||||
"mk" : _("Macedonian"),
|
||||
"nb" : _("Norwegian Bokmal"),
|
||||
"nl" : _("Dutch"),
|
||||
"nn" : _("Norwegian Nynorsk"),
|
||||
"pl" : _("Polish"),
|
||||
"pt" : _("Portuguese"),
|
||||
"ro" : _("Romanian"),
|
||||
"ru" : _("Russian"),
|
||||
"sk" : _("Slovak"),
|
||||
"sl" : _("Slovenian"),
|
||||
"sq" : _("Albanian"),
|
||||
"sv" : _("Swedish"),
|
||||
"tr" : _("Turkish"),
|
||||
"uk" : _("Ukrainian"),
|
||||
"vi" : _("Vietnamese"),
|
||||
"zh" : _("Chinese")
|
||||
}
|
||||
|
||||
_COUNTRY_MAP = {
|
||||
"BR" : _("Brazil"),
|
||||
"CN" : _("China"),
|
||||
"PT" : _("Portugal")
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Public Functions
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
def get_language_string(lang_code):
|
||||
"""
|
||||
Given a language code of the form "lang_region", return a text string
|
||||
representing that language.
|
||||
"""
|
||||
code_parts = lang_code.rsplit("_")
|
||||
|
||||
lang = code_parts[0]
|
||||
if lang in _LANG_MAP:
|
||||
lang = _LANG_MAP[lang]
|
||||
|
||||
if len(code_parts) > 1:
|
||||
country = code_parts[1]
|
||||
if country in _COUNTRY_MAP:
|
||||
country = _COUNTRY_MAP[country]
|
||||
retstr = _("%(language)s (%(country)s)") % \
|
||||
{ 'language' : lang, 'country' : country }
|
||||
else:
|
||||
retstr = lang
|
||||
|
||||
return retstr
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
|
@ -53,7 +53,7 @@ from gramps.gen.plug.report import Report
|
||||
from gramps.gen.plug.report import utils as ReportUtils
|
||||
from gramps.gen.plug.report import MenuReportOptions
|
||||
from gramps.plugins.lib.libnarrate import Narrator
|
||||
from gramps.plugins.lib.libtranslate import Translator, get_language_string
|
||||
from gramps.plugins.lib.libtranslate import Translator
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -300,8 +300,9 @@ class AncestorOptions(MenuReportOptions):
|
||||
trans = EnumeratedListOption(_("Translation"),
|
||||
Translator.DEFAULT_TRANSLATION_STR)
|
||||
trans.add_item(Translator.DEFAULT_TRANSLATION_STR, _("Default"))
|
||||
for language in glocale.get_available_translations():
|
||||
trans.add_item(language, get_language_string(language))
|
||||
languages = glocale.get_language_dict()
|
||||
for language in sorted(languages):
|
||||
trans.add_item(languages[language], language)
|
||||
trans.set_help(_("The translation to be used for the report."))
|
||||
menu.add_option(category_name, "trans", trans)
|
||||
|
||||
|
@ -56,7 +56,7 @@ from gramps.gen.plug.report import endnotes
|
||||
from gramps.gen.plug.report import utils as ReportUtils
|
||||
from gramps.gen.plug.report import MenuReportOptions
|
||||
from gramps.plugins.lib.libnarrate import Narrator
|
||||
from gramps.plugins.lib.libtranslate import Translator, get_language_string
|
||||
from gramps.plugins.lib.libtranslate import Translator
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -754,8 +754,9 @@ class DetAncestorOptions(MenuReportOptions):
|
||||
trans = EnumeratedListOption(_("Translation"),
|
||||
Translator.DEFAULT_TRANSLATION_STR)
|
||||
trans.add_item(Translator.DEFAULT_TRANSLATION_STR, _("Default"))
|
||||
for language in glocale.get_available_translations():
|
||||
trans.add_item(language, get_language_string(language))
|
||||
languages = glocale.get_language_dict()
|
||||
for language in sorted(languages):
|
||||
trans.add_item(languages[language], language)
|
||||
trans.set_help(_("The translation to be used for the report."))
|
||||
addopt("trans", trans)
|
||||
|
||||
|
@ -60,7 +60,7 @@ from gramps.gen.plug.report import endnotes
|
||||
from gramps.gen.plug.report import utils as ReportUtils
|
||||
from gramps.gen.plug.report import MenuReportOptions
|
||||
from gramps.plugins.lib.libnarrate import Narrator
|
||||
from gramps.plugins.lib.libtranslate import Translator, get_language_string
|
||||
from gramps.plugins.lib.libtranslate import Translator
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -929,8 +929,9 @@ class DetDescendantOptions(MenuReportOptions):
|
||||
trans = EnumeratedListOption(_("Translation"),
|
||||
Translator.DEFAULT_TRANSLATION_STR)
|
||||
trans.add_item(Translator.DEFAULT_TRANSLATION_STR, _("Default"))
|
||||
for language in glocale.get_available_translations():
|
||||
trans.add_item(language, get_language_string(language))
|
||||
languages = glocale.get_language_dict()
|
||||
for language in sorted(languages):
|
||||
trans.add_item(languages[language], language)
|
||||
trans.set_help(_("The translation to be used for the report."))
|
||||
add_option("trans", trans)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user