From 59457923fa28cbeacb6aaae6f569a2a6a3f9e57b Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Sun, 20 Oct 2013 16:46:53 +0000 Subject: [PATCH] 7124: Complete Individual Report does incomplete translation svn: r23354 --- gramps/gen/plug/report/endnotes.py | 20 ++++--------------- gramps/gen/utils/string.py | 20 ++++++++++++------- gramps/gui/editors/filtereditor.py | 13 ++++++------ .../filters/sidebar/_citationsidebarfilter.py | 16 +++++++-------- gramps/gui/merge/mergecitation.py | 6 +++--- .../gui/views/treemodels/citationbasemodel.py | 7 ++++--- gramps/plugins/textreport/indivcomplete.py | 2 +- gramps/plugins/tool/mergecitations.py | 4 ++-- gramps/plugins/tool/testcasegenerator.py | 4 ++-- gramps/plugins/webreport/narrativeweb.py | 8 +++++--- 10 files changed, 49 insertions(+), 51 deletions(-) diff --git a/gramps/gen/plug/report/endnotes.py b/gramps/gen/plug/report/endnotes.py index 0f406f8c3..5f797e7a2 100644 --- a/gramps/gen/plug/report/endnotes.py +++ b/gramps/gen/plug/report/endnotes.py @@ -31,7 +31,7 @@ from ..docgen import FontStyle, ParagraphStyle, FONT_SANS_SERIF from ...lib import NoteType, Citation from ...const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext -from ...utils.string import confidence +from ...utils.string import conf_strings def add_endnote_styles(style_sheet): """ @@ -198,21 +198,9 @@ def _format_ref_text(ref, key, elocale): ref_txt = ref.get_page() # Print only confidence level if it is not Normal - if (ref.get_confidence_level() != Citation.CONF_NORMAL - and elocale == glocale): # FIXME - # the correct fix would be to enable deferred translation for at - # least the "confidence" list of strings (in gen/utils/string.py), - # and possibly others too if they need deferred translation, but that - # would require searching out every use of a "confidence" string and - # translating it there, either to the UI language or to a "deferred" - # language (e.g. when used in a report, as here in this module), but - # that would require an immense amount of time and testing and since - # a release is imminent this is not the time to consider that, so I - # have instead added the above line, which will disable the typeout - # of any "confidence" rating /if/ a translated value is needed, while - # continuing to show the "confidence" for the normal case of a user - # running a report in their own language (when elocale==glocale) - ref_txt += " [" + confidence[ref.get_confidence_level()] + "]" + if ref.get_confidence_level() != Citation.CONF_NORMAL: + ref_txt += " [" + elocale.translation.gettext( + conf_strings[ref.get_confidence_level()]) + "]" return ref_txt diff --git a/gramps/gen/utils/string.py b/gramps/gen/utils/string.py index 497e9d3d7..ca89d7939 100644 --- a/gramps/gen/utils/string.py +++ b/gramps/gen/utils/string.py @@ -35,6 +35,10 @@ from ..lib import Person, Citation, FamilyRelType from ..const import GRAMPS_LOCALE as glocale _ = glocale.translation.sgettext +def _T_(value): # enable deferred translations (see Python docs 22.1.3.4) + return value +# _T_ is a gramps-defined keyword -- see po/update_po.py and po/genpot.sh + #------------------------------------------------------------------------- # # Integer to String mappings for constants @@ -49,13 +53,15 @@ gender = { def format_gender( type): return gender.get(type[0], _("Invalid")) -confidence = { - Citation.CONF_VERY_HIGH : _("Very High"), - Citation.CONF_HIGH : _("High"), - Citation.CONF_NORMAL : _("Normal"), - Citation.CONF_LOW : _("Low"), - Citation.CONF_VERY_LOW : _("Very Low"), - } +conf_strings = { + Citation.CONF_VERY_HIGH : _T_("Very High"), + Citation.CONF_HIGH : _T_("High"), + Citation.CONF_NORMAL : _T_("Normal"), + Citation.CONF_LOW : _T_("Low"), + Citation.CONF_VERY_LOW : _T_("Very Low"), + } + # note that a list /very/ similar to this is in EditCitation._setup_fields + # but that has the glocale's translated values since it is used in the UI family_rel_descriptions = { FamilyRelType.MARRIED : _("A legal or common-law relationship " diff --git a/gramps/gui/editors/filtereditor.py b/gramps/gui/editors/filtereditor.py index e5ab9f838..d1d863ddf 100644 --- a/gramps/gui/editors/filtereditor.py +++ b/gramps/gui/editors/filtereditor.py @@ -53,8 +53,10 @@ from gi.repository import GObject # GRAMPS modules # #------------------------------------------------------------------------- +from gramps.gen.const import GRAMPS_LOCALE as glocale +_ = glocale.translation.sgettext from gramps.gen.filters import (GenericFilterFactory, FilterList, - reload_custom_filters) + reload_custom_filters) from gramps.gen.filters.rules._matchesfilterbase import MatchesFilterBase from ..listmodel import ListModel from ..managedwindow import ManagedWindow @@ -62,15 +64,14 @@ from ..dialog import QuestionDialog from gramps.gen.const import RULE_GLADE, URL_MANUAL_PAGE from ..display import display_help from gramps.gen.errors import WindowActiveError -from gramps.gen.const import GRAMPS_LOCALE as glocale -_ = glocale.translation.sgettext -from gramps.gen.lib import AttributeType, EventType, FamilyRelType, NameOriginType, NameType, NoteType +from gramps.gen.lib import (AttributeType, EventType, FamilyRelType, + NameOriginType, NameType, NoteType) from gramps.gen.filters import rules from ..autocomp import StandardCustomSelector, fill_entry from ..selectors import SelectorFactory from gramps.gen.display.name import displayer as _nd from gramps.gen.utils.db import family_name -from gramps.gen.utils.string import confidence +from gramps.gen.utils.string import conf_strings from gramps.gen.constfunc import cuni from ..widgets import DateEntry @@ -553,7 +554,7 @@ class EditRule(ManagedWindow): t = MyList(taglist, taglist) elif v == _('Confidence level:'): t = MyList(list(map(str, list(range(5)))), - [confidence[i] for i in range(5)]) + [_(conf_strings[i]) for i in range(5)]) elif v == _('Date:'): t = DateEntry(self.uistate, self.track) else: diff --git a/gramps/gui/filters/sidebar/_citationsidebarfilter.py b/gramps/gui/filters/sidebar/_citationsidebarfilter.py index 5cc8352bd..4c08d1411 100644 --- a/gramps/gui/filters/sidebar/_citationsidebarfilter.py +++ b/gramps/gui/filters/sidebar/_citationsidebarfilter.py @@ -50,7 +50,7 @@ from gramps.gen.filters import GenericFilterFactory, rules from gramps.gen.filters.rules.citation import (RegExpIdOf, HasCitation, HasTag, HasNoteRegexp, MatchesFilter, HasSource, RegExpSourceIdOf) -from gramps.gen.utils.string import confidence +from gramps.gen.utils.string import conf_strings GenericCitationFilter = GenericFilterFactory('Citation') #------------------------------------------------------------------------- # @@ -73,10 +73,10 @@ class CitationSidebarFilter(SidebarFilter): self.filter_conf = Gtk.ComboBox() model = Gtk.ListStore(str) - for conf_value in sorted(confidence.keys()): - model.append((confidence[conf_value],)) + for conf_value in sorted(conf_strings.keys()): + model.append((_(conf_strings[conf_value]),)) self.filter_conf.set_model(model) - self.filter_conf.set_active(2) # Citation.CONF_NORMAL + self.filter_conf.set_active(Citation.CONF_NORMAL) self.filter_note = Gtk.Entry() @@ -132,7 +132,7 @@ class CitationSidebarFilter(SidebarFilter): self.filter_id.set_text('') self.filter_page.set_text('') self.filter_date.set_text('') - self.filter_conf.set_active(2) + self.filter_conf.set_active(Citation.CONF_NORMAL) self.filter_note.set_text('') self.tag.set_active(0) self.generic.set_active(0) @@ -153,9 +153,9 @@ class CitationSidebarFilter(SidebarFilter): model = self.filter_conf.get_model() node = self.filter_conf.get_active_iter() conf_name = model.get_value(node, 0) # The value is actually the text - conf = 2 - for i in list(confidence.keys()): - if confidence[i] == conf_name: + conf = Citation.CONF_NORMAL + for i in list(conf_strings.keys()): + if _(conf_strings[i]) == conf_name: conf = i break # conf = self.citn.get_confidence_level() diff --git a/gramps/gui/merge/mergecitation.py b/gramps/gui/merge/mergecitation.py index d9f0c172f..38ede9a24 100644 --- a/gramps/gui/merge/mergecitation.py +++ b/gramps/gui/merge/mergecitation.py @@ -36,7 +36,7 @@ from gramps.gen.const import URL_MANUAL_PAGE from ..display import display_help from ..managedwindow import ManagedWindow from gramps.gen.datehandler import get_date -from gramps.gen.utils.string import confidence +from gramps.gen.utils.string import conf_strings from gramps.gen.merge import MergeCitationQuery #------------------------------------------------------------------------- @@ -92,8 +92,8 @@ class MergeCitation(ManagedWindow): entry1 = self.get_widget("confidence1") entry2 = self.get_widget("confidence2") - entry1.set_text(confidence[self.citation1.get_confidence_level()]) - entry2.set_text(confidence[self.citation2.get_confidence_level()]) + entry1.set_text(_(conf_strings[self.citation1.get_confidence_level()])) + entry2.set_text(_(conf_strings[self.citation2.get_confidence_level()])) if entry1.get_text() == entry2.get_text(): for widget_name in ('confidence1', 'confidence2', 'confidence_btn1', 'confidence_btn2'): diff --git a/gramps/gui/views/treemodels/citationbasemodel.py b/gramps/gui/views/treemodels/citationbasemodel.py index 0386d6651..c2206c979 100644 --- a/gramps/gui/views/treemodels/citationbasemodel.py +++ b/gramps/gui/views/treemodels/citationbasemodel.py @@ -39,12 +39,13 @@ LOG = logging.getLogger(".citation") # GRAMPS modules # #------------------------------------------------------------------------- +from gramps.gen.const import GRAMPS_LOCALE as glocale +_ = glocale.translation.gettext from gramps.gen.datehandler import format_time, get_date, get_date_valid from gramps.gen.lib import Citation -from gramps.gen.utils.string import confidence +from gramps.gen.utils.string import conf_strings from gramps.gen.config import config from gramps.gen.constfunc import cuni -from gramps.gen.const import GRAMPS_LOCALE as glocale #------------------------------------------------------------------------- # @@ -116,7 +117,7 @@ class CitationBaseModel(object): return cuni(data[COLUMN_PAGE]) def citation_confidence(self, data): - return cuni(confidence[data[COLUMN_CONFIDENCE]]) + return cuni(_(conf_strings[data[COLUMN_CONFIDENCE]])) def citation_private(self, data): if data[COLUMN_PRIV]: diff --git a/gramps/plugins/textreport/indivcomplete.py b/gramps/plugins/textreport/indivcomplete.py index e1625a081..75b772172 100644 --- a/gramps/plugins/textreport/indivcomplete.py +++ b/gramps/plugins/textreport/indivcomplete.py @@ -223,7 +223,7 @@ class IndivCompleteReport(Report): # Groups with more than one type column_1 = self._(self._get_type(event.get_type())) if role not in (EventRoleType.PRIMARY, EventRoleType.FAMILY): - column_1 = column_1 + ' (' + str(role) + ')' + column_1 = column_1 + ' (' + self._(role.xml_str()) + ')' column_2 = combine('%s, %s', '%s', description, date_place) else: # Groups with a single type (remove event type from first column) diff --git a/gramps/plugins/tool/mergecitations.py b/gramps/plugins/tool/mergecitations.py index 08e6bd0e4..6f2e74056 100644 --- a/gramps/plugins/tool/mergecitations.py +++ b/gramps/plugins/tool/mergecitations.py @@ -47,7 +47,7 @@ from gi.repository import Gtk # GRAMPS modules # #------------------------------------------------------------------------- -from gramps.gen.utils.string import confidence +from gramps.gen.utils.string import conf_strings from gramps.gen.const import URL_MANUAL_PAGE from gramps.gui.utils import ProgressMeter from gramps.gui.plug import tool @@ -204,7 +204,7 @@ class MergeCitations(tool.BatchTool,ManagedWindow): key += "\n" + get_date(citation) if fields != IGNORE_CONFIDENCE and fields != IGNORE_BOTH: key += "\n" + \ - confidence[citation.get_confidence_level()] + conf_strings[citation.get_confidence_level()] if key in dict and \ (not dont_merge_notes or len(citation.note_list) == 0): citation_match_handle = dict[key] diff --git a/gramps/plugins/tool/testcasegenerator.py b/gramps/plugins/tool/testcasegenerator.py index 8e98ef08c..a60a8f322 100644 --- a/gramps/plugins/tool/testcasegenerator.py +++ b/gramps/plugins/tool/testcasegenerator.py @@ -62,7 +62,7 @@ from gramps.gen.lib import StyledText, StyledTextTag, StyledTextTagType from gramps.gen.db import DbTxn from gramps.gen.mime import get_type from gramps.gui.plug import tool -from gramps.gen.utils.string import confidence +from gramps.gen.utils.string import conf_strings from gramps.gui.utils import ProgressMeter from gramps.gen.utils.lds import TEMPLES from gramps.gen.db.dbconst import * @@ -1735,7 +1735,7 @@ class TestcaseGenerator(tool.BatchTool): #if randint(0,1) == 1: # (year, d) = self.rand_date( ) # o.set_date_object( d) - o.set_confidence_level(choice(list(confidence.keys()))) + o.set_confidence_level(choice(list(conf_strings.keys()))) if issubclass(o.__class__,gen.lib.tagbase.TagBase): if randint(0,1) == 1: diff --git a/gramps/plugins/webreport/narrativeweb.py b/gramps/plugins/webreport/narrativeweb.py index a30ba3b0a..f753f8985 100644 --- a/gramps/plugins/webreport/narrativeweb.py +++ b/gramps/plugins/webreport/narrativeweb.py @@ -123,7 +123,7 @@ from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import MenuReportOptions from gramps.gen.utils.config import get_researcher -from gramps.gen.utils.string import confidence +from gramps.gen.utils.string import conf_strings from gramps.gen.utils.file import media_path_full from gramps.gen.utils.alive import probably_alive from gramps.gen.utils.db import get_source_and_citation_referents @@ -2356,9 +2356,11 @@ class BasePage(object): for key, sref in citation_ref_list: cit_ref_li = Html("li", id="sref%d%s" % (cindex, key)) tmp = Html("ul") - conf = confidence.get(sref.confidence, _('Unknown')) - if conf == _('Normal'): + conf = conf_strings.get(sref.confidence, _('Unknown')) + if conf == conf_strings[Citation.CONF_NORMAL]: conf = None + else: + conf = _(conf) for (label, data) in [ [_("Date"), _dd.display(sref.date)], [_("Page"), sref.page],