From f141905e0b3bb1bffaa50185058e165c291b499e Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Wed, 12 Dec 2007 03:59:18 +0000 Subject: [PATCH] 2007-12-11 Douglas S. Blank * src/GrampsCfg.py: added keyword and translation functions * src/Utils.py: Name Display Editor should work in locale svn: r9491 --- ChangeLog | 4 ++++ src/GrampsCfg.py | 26 +++++++++++++++----------- src/Utils.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index e93e1be32..34813d8f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-12-11 Douglas S. Blank + * src/GrampsCfg.py: added keyword and translation functions + * src/Utils.py: Name Display Editor should work in locale + 2007-12-10 Douglas S. Blank * src/ViewManager.py: exposed a private method via a new method, post_load_newdb() diff --git a/src/GrampsCfg.py b/src/GrampsCfg.py index 4fc787e95..96eb5ba58 100644 --- a/src/GrampsCfg.py +++ b/src/GrampsCfg.py @@ -301,17 +301,18 @@ class GrampsPreferences(ManagedWindow.ManagedWindow): Create a common model for ComboBox and TreeView """ name_format_model = gtk.ListStore(int, str, str, str) - index = 0 the_index = 0 - for num, name, fmt_str, act in _nd.get_name_format(): + translation = fmt_str + for key in Utils.get_keywords(): + if key in translation: + translation = translation.replace(key, Utils.get_translation_from_keyword(key)) self.examplename.set_display_as(num) name_format_model.append( - row=[num, name, fmt_str, _nd.display_name(self.examplename)]) + row=[num, translation, fmt_str, _nd.display_name(self.examplename)]) if num == active: the_index = index index += 1 - return name_format_model, the_index def __new_name(self, obj): @@ -319,8 +320,8 @@ class GrampsPreferences(ManagedWindow.ManagedWindow): _("Given"), _("Common"), )) - i = _nd.add_name_format(f, f) - node = self.fmt_model.append(row=[i, f, f, + i = _nd.add_name_format(f, f.lower()) + node = self.fmt_model.append(row=[i, f, f.lower(), _nd.format_str(self.examplename, f)]) path = self.fmt_model.get_path(node) self.format_list.set_cursor(path, @@ -340,16 +341,19 @@ class GrampsPreferences(ManagedWindow.ManagedWindow): database is simply changing the contents of the name file. """ if len(new_text) > 0 and text != new_text: + pattern = new_text + for key in Utils.get_translations(): + if key in pattern: + pattern = pattern.replace(key, Utils.get_keyword_from_translation(key)) num, name, fmt = self.selected_fmt[COL_NUM:COL_EXPL] node = self.fmt_model.get_iter(path) oldname = self.fmt_model.get_value(node, COL_NAME) - #self.fmt_model.set_value(node, COL_NAME, new_text) - exmpl = _nd.format_str(self.examplename, new_text) + exmpl = _nd.format_str(self.examplename, pattern) self.fmt_model.set(self.iter, COL_NAME, new_text, - COL_FMT, new_text, + COL_FMT, pattern, COL_EXPL, exmpl) - self.selected_fmt = (num, new_text, new_text, exmpl) - _nd.edit_name_format(num, new_text, new_text) + self.selected_fmt = (num, new_text, pattern, exmpl) + _nd.edit_name_format(num, new_text, pattern) self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True, only_active=False) diff --git a/src/Utils.py b/src/Utils.py index 29c69e8ff..640a1b488 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -1089,3 +1089,50 @@ def profile(func, *args): stats.print_stats(100) stats.print_callers(100) +#------------------------------------------------------------------------- +# +# Keyword translation interface +# +#------------------------------------------------------------------------- + +# keyword, code, translated standard, translated upper +KEYWORDS = [("title", "t", _("Title"), _("TITLE")), + ("given", "f", _("Given"), _("GIVEN")), + ("prefix", "p", _("Prefix"), _("PREFIX")), + ("surname", "l", _("Surname"), _("SURNAME")), + ("suffix", "s", _("Suffix"), _("SUFFIX")), + ("patronymic","y", _("Patronymic"),_("PATRONYMIC")), + ("call", "c", _("Call"), _("CALL")), + ("common", "x", _("Common"), _("COMMON")), + ("initials", "i", _("Initials"), _("INITIALS")) + ] +KEY_TO_TRANS = {} +TRANS_TO_KEY = {} +for (key, code, standard, upper) in KEYWORDS: + KEY_TO_TRANS[key] = standard + KEY_TO_TRANS[key.upper()] = upper + KEY_TO_TRANS["%" + ("%s" % code)] = standard + KEY_TO_TRANS["%" + ("%s" % code.upper())] = upper + TRANS_TO_KEY[standard] = key + TRANS_TO_KEY[upper] = key + +def get_translation_from_keyword(keyword): + """ Return the translation of keyword """ + return KEY_TO_TRANS.get(keyword, keyword) + +def get_keyword_from_translation(word): + """ Return the keyword of translation """ + return TRANS_TO_KEY.get(word, word) + +def get_keywords(): + """ Get all keywords, longest to shortest """ + keys = KEY_TO_TRANS.keys() + keys.sort(lambda a,b: -cmp(len(a), len(b))) + return keys + +def get_translations(): + """ Get all translations, longest to shortest """ + trans = TRANS_TO_KEY.keys() + trans.sort(lambda a,b: -cmp(len(a), len(b))) + return trans +