2007-12-12 Douglas S. Blank <dblank@doraemon.brynmawr.edu>

* src/GrampsCfg.py: added Translation -> Pattern -> Translation
	so that one can see fully translated text, even if they type in
	English, or %codes
	* src/Utils.py: Fixed two bugs in translations of keywords
	* src/test/utils_test.py: unit tests for keywords/translations



svn: r9493
This commit is contained in:
Doug Blank 2007-12-12 16:24:40 +00:00
parent 734b05fd44
commit 9871fcf645
4 changed files with 84 additions and 4 deletions

View File

@ -1,3 +1,10 @@
2007-12-12 Douglas S. Blank <dblank@doraemon.brynmawr.edu>
* src/GrampsCfg.py: added Translation -> Pattern -> Translation
so that one can see fully translated text, even if they type in
English, or %codes
* src/Utils.py: Fixed two bugs in translations of keywords
* src/test/utils_test.py: unit tests for keywords/translations
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

View File

@ -341,19 +341,25 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
database is simply changing the contents of the name file.
"""
if len(new_text) > 0 and text != new_text:
# build a pattern from translated pattern:
pattern = new_text
for key in Utils.get_translations():
if key in pattern:
pattern = pattern.replace(key, Utils.get_keyword_from_translation(key))
# now build up a proper translation:
translation = pattern
for key in Utils.get_keywords():
if key in translation:
translation = translation.replace(key, Utils.get_translation_from_keyword(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)
exmpl = _nd.format_str(self.examplename, pattern)
self.fmt_model.set(self.iter, COL_NAME, new_text,
self.fmt_model.set(self.iter, COL_NAME, translation,
COL_FMT, pattern,
COL_EXPL, exmpl)
self.selected_fmt = (num, new_text, pattern, exmpl)
_nd.edit_name_format(num, new_text, pattern)
self.selected_fmt = (num, translation, pattern, exmpl)
_nd.edit_name_format(num, translation, pattern)
self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True,
only_active=False)

View File

@ -1113,8 +1113,9 @@ for (key, code, standard, upper) in KEYWORDS:
KEY_TO_TRANS[key.upper()] = upper
KEY_TO_TRANS["%" + ("%s" % code)] = standard
KEY_TO_TRANS["%" + ("%s" % code.upper())] = upper
TRANS_TO_KEY[standard.lower()] = key
TRANS_TO_KEY[standard] = key
TRANS_TO_KEY[upper] = key
TRANS_TO_KEY[upper] = key.upper()
def get_translation_from_keyword(keyword):
""" Return the translation of keyword """

66
src/test/utils_test.py Normal file
View File

@ -0,0 +1,66 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2007 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: $
""" Unittest for testing ... """
__author__ = "Douglas S. Blank <dblank@cs.brynmawr.edu>"
__revision__ = "$Revision: $"
import unittest
from test import test_util
test_util.path_append_parent()
import Utils
class TestCase(unittest.TestCase):
count = 1
def __init__(self, *args):
method_name = args[0] % self.count
TestCase.count += 1
self.__dict__[method_name] = lambda: self.helper(*args)
unittest.TestCase.__init__(self, method_name)
def helper(self, *args):
method_name, test_type, item1, item2 = args
if test_type == "keyword":
result = Utils.get_translation_from_keyword(item1)
self.assertTrue(result == item2,
"get_translation_from_keyword('%s') returned '%s' rather than '%s'" % (item1, result, item2))
elif test_type == "translation":
result = Utils.get_keyword_from_translation(item1)
self.assertTrue(result == item2,
"get_keyword_from_translation('%s') returned '%s' rather than '%s'" % (item1, result, item2))
else:
raise AttributeError, "test called incorrectly"
def suite1():
"""
"""
suite = unittest.TestSuite()
for line in Utils.KEYWORDS:
keyword, code, standard, upper = line
suite.addTest(TestCase('keyword-%04d', 'keyword', keyword, standard))
suite.addTest(TestCase('translation-%04d', 'translation', standard, keyword))
suite.addTest(TestCase('translation-%04d', 'translation', upper, keyword.upper()))
return suite
if __name__ == "__main__":
unittest.TextTestRunner().run(suite1())