Add translated language and country strings to the report transation option.
svn: r13790
This commit is contained in:
parent
80138e8313
commit
ec81292e52
@ -30,6 +30,7 @@ Translator class for use by plugins.
|
|||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
import gettext
|
import gettext
|
||||||
|
_ = gettext.gettext
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -39,6 +40,75 @@ import gettext
|
|||||||
import TransUtils
|
import TransUtils
|
||||||
import DateHandler
|
import DateHandler
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Private Constants
|
||||||
|
#
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
_LANG_MAP = {
|
||||||
|
"bg" : _("Bulgarian"),
|
||||||
|
"ca" : _("Catalan"),
|
||||||
|
"cs" : _("Czech"),
|
||||||
|
"da" : _("Danish"),
|
||||||
|
"de" : _("German"),
|
||||||
|
"en" : _("English"),
|
||||||
|
"eo" : _("Esperanto"),
|
||||||
|
"es" : _("Spanish"),
|
||||||
|
"fi" : _("Finnish"),
|
||||||
|
"fr" : _("French"),
|
||||||
|
"he" : _("Hebrew"),
|
||||||
|
"hr" : _("Croatian"),
|
||||||
|
"hu" : _("Hungarian"),
|
||||||
|
"it" : _("Italian"),
|
||||||
|
"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"),
|
||||||
|
"zh" : _("Chinese")
|
||||||
|
}
|
||||||
|
|
||||||
|
_COUNTRY_MAP = {
|
||||||
|
"BR" : _("Brazil"),
|
||||||
|
"CN" : _("China")
|
||||||
|
}
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Translator
|
# Translator
|
||||||
@ -70,7 +140,10 @@ class Translator:
|
|||||||
self.__trans = gettext.translation(TransUtils.get_localedomain(),
|
self.__trans = gettext.translation(TransUtils.get_localedomain(),
|
||||||
languages=[lang],
|
languages=[lang],
|
||||||
fallback=True)
|
fallback=True)
|
||||||
self.__dd = DateHandler.LANG_TO_DISPLAY[lang](None)
|
if lang in DateHandler.LANG_TO_DISPLAY:
|
||||||
|
self.__dd = DateHandler.LANG_TO_DISPLAY[lang](None)
|
||||||
|
else:
|
||||||
|
self.__dd = DateHandler.displayer
|
||||||
|
|
||||||
def get_text(self, message):
|
def get_text(self, message):
|
||||||
"""
|
"""
|
||||||
|
@ -47,7 +47,7 @@ from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle,
|
|||||||
from ReportBase import Report, ReportUtils, MenuReportOptions
|
from ReportBase import Report, ReportUtils, MenuReportOptions
|
||||||
import TransUtils
|
import TransUtils
|
||||||
from libnarrate import Narrator
|
from libnarrate import Narrator
|
||||||
from libtranslate import Translator
|
from libtranslate import Translator, get_language_string
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -273,7 +273,7 @@ class AncestorOptions(MenuReportOptions):
|
|||||||
Translator.DEFAULT_TRANSLATION_STR)
|
Translator.DEFAULT_TRANSLATION_STR)
|
||||||
trans.add_item(Translator.DEFAULT_TRANSLATION_STR, _("default"))
|
trans.add_item(Translator.DEFAULT_TRANSLATION_STR, _("default"))
|
||||||
for language in TransUtils.get_available_translations():
|
for language in TransUtils.get_available_translations():
|
||||||
trans.add_item(language, language)
|
trans.add_item(language, get_language_string(language))
|
||||||
trans.set_help(_("The translation to be used for the report."))
|
trans.set_help(_("The translation to be used for the report."))
|
||||||
menu.add_option(category_name, "trans", trans)
|
menu.add_option(category_name, "trans", trans)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user