2007-12-11 Douglas S. Blank <dblank@cs.brynmawr.edu>
* src/GrampsCfg.py: added keyword and translation functions * src/Utils.py: Name Display Editor should work in locale svn: r9491
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
2007-12-11 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
||||||
|
* src/GrampsCfg.py: added keyword and translation functions
|
||||||
|
* src/Utils.py: Name Display Editor should work in locale
|
||||||
|
|
||||||
2007-12-10 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
2007-12-10 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
||||||
* src/ViewManager.py: exposed a private method via a new method,
|
* src/ViewManager.py: exposed a private method via a new method,
|
||||||
post_load_newdb()
|
post_load_newdb()
|
||||||
|
@@ -301,17 +301,18 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
|||||||
Create a common model for ComboBox and TreeView
|
Create a common model for ComboBox and TreeView
|
||||||
"""
|
"""
|
||||||
name_format_model = gtk.ListStore(int, str, str, str)
|
name_format_model = gtk.ListStore(int, str, str, str)
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
the_index = 0
|
the_index = 0
|
||||||
|
|
||||||
for num, name, fmt_str, act in _nd.get_name_format():
|
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)
|
self.examplename.set_display_as(num)
|
||||||
name_format_model.append(
|
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
|
if num == active: the_index = index
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
return name_format_model, the_index
|
return name_format_model, the_index
|
||||||
|
|
||||||
def __new_name(self, obj):
|
def __new_name(self, obj):
|
||||||
@@ -319,8 +320,8 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
|||||||
_("Given"),
|
_("Given"),
|
||||||
_("Common"),
|
_("Common"),
|
||||||
))
|
))
|
||||||
i = _nd.add_name_format(f, f)
|
i = _nd.add_name_format(f, f.lower())
|
||||||
node = self.fmt_model.append(row=[i, f, f,
|
node = self.fmt_model.append(row=[i, f, f.lower(),
|
||||||
_nd.format_str(self.examplename, f)])
|
_nd.format_str(self.examplename, f)])
|
||||||
path = self.fmt_model.get_path(node)
|
path = self.fmt_model.get_path(node)
|
||||||
self.format_list.set_cursor(path,
|
self.format_list.set_cursor(path,
|
||||||
@@ -340,16 +341,19 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
|||||||
database is simply changing the contents of the name file.
|
database is simply changing the contents of the name file.
|
||||||
"""
|
"""
|
||||||
if len(new_text) > 0 and text != new_text:
|
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]
|
num, name, fmt = self.selected_fmt[COL_NUM:COL_EXPL]
|
||||||
node = self.fmt_model.get_iter(path)
|
node = self.fmt_model.get_iter(path)
|
||||||
oldname = self.fmt_model.get_value(node, COL_NAME)
|
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, pattern)
|
||||||
exmpl = _nd.format_str(self.examplename, new_text)
|
|
||||||
self.fmt_model.set(self.iter, COL_NAME, new_text,
|
self.fmt_model.set(self.iter, COL_NAME, new_text,
|
||||||
COL_FMT, new_text,
|
COL_FMT, pattern,
|
||||||
COL_EXPL, exmpl)
|
COL_EXPL, exmpl)
|
||||||
self.selected_fmt = (num, new_text, new_text, exmpl)
|
self.selected_fmt = (num, new_text, pattern, exmpl)
|
||||||
_nd.edit_name_format(num, new_text, new_text)
|
_nd.edit_name_format(num, new_text, pattern)
|
||||||
self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True,
|
self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True,
|
||||||
only_active=False)
|
only_active=False)
|
||||||
|
|
||||||
|
47
src/Utils.py
47
src/Utils.py
@@ -1089,3 +1089,50 @@ def profile(func, *args):
|
|||||||
stats.print_stats(100)
|
stats.print_stats(100)
|
||||||
stats.print_callers(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
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user