1# 2# Gramps - a GTK+/GNOME based genealogy program 3# 4# Copyright (C) 2000-2007 Donald N. Allingham 5# Copyright (C) 2009 Gary Burton 6# Copyright (C) 2011 Tim G L Lyons 7# 8# This program is free software; you can redistribute it and/or modify 9# it under the terms of the GNU General Public License as published by 10# the Free Software Foundation; either version 2 of the License, or 11# (at your option) any later version. 12# 13# This program is distributed in the hope that it will be useful, 14# but WITHOUT ANY WARRANTY; without even the implied warranty of 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16# GNU General Public License for more details. 17# 18# You should have received a copy of the GNU General Public License 19# along with this program; if not, write to the Free Software 20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21# 22 23""" 24Keyword translation interface 25""" 26 27# keyword, code, translated standard, translated upper 28# in gen.display.name.py we find: 29# 't' : title = title 30# 'f' : given = given (first names) 31# 'l' : surname = full surname (lastname) 32# 'c' : call = callname 33# 'x' : common = nick name if existing, otherwise first first name (common name) 34# 'i' : initials = initials of the first names 35# 'm' : primary = primary surname (main) 36# '0m': primary[pre]= prefix primary surname (main) 37# '1m': primary[sur]= surname primary surname (main) 38# '2m': primary[con]= connector primary surname (main) 39# 'y' : patronymic = pa/matronymic surname (father/mother) - assumed unique 40# '0y': patronymic[pre] = prefix " 41# '1y': patronymic[sur] = surname " 42# '2y': patronymic[con] = connector " 43# 'o' : notpatronymic = surnames without pa/matronymic and primary 44# 'r' : rest = non primary surnames 45# 'p' : prefix = list of all prefixes 46# 'q' : rawsurnames = surnames without prefixes and connectors 47# 's' : suffix = suffix 48# 'n' : nickname = nick name 49# 'g' : familynick = family nick name 50 51from ..const import GRAMPS_LOCALE as glocale 52_ = glocale.translation.sgettext 53 54KEYWORDS = [("title", "t", _("Person|Title"), _("Person|TITLE")), 55 ("given", "f", _("Given"), _("GIVEN")), 56 ("surname", "l", _("Surname"), _("SURNAME")), 57 ("call", "c", _("Name|Call"), _("Name|CALL")), 58 ("common", "x", _("Name|Common"), _("Name|COMMON")), 59 ("initials", "i", _("Initials"), _("INITIALS")), 60 ("suffix", "s", _("Suffix"), _("SUFFIX")), 61 ("primary", "m", _("Name|Primary"), _("PRIMARY")), 62 ("primary[pre]", "0m", _("Primary[pre]"), _("PRIMARY[PRE]")), 63 ("primary[sur]", "1m", _("Primary[sur]"), _("PRIMARY[SUR]")), 64 ("primary[con]", "2m", _("Primary[con]"), _("PRIMARY[CON]")), 65 ("patronymic", "y", _("Patronymic"), _("PATRONYMIC")), 66 ("patronymic[pre]", "0y", _("Patronymic[pre]"), _("PATRONYMIC[PRE]")), 67 ("patronymic[sur]", "1y", _("Patronymic[sur]"), _("PATRONYMIC[SUR]")), 68 ("patronymic[con]", "2y", _("Patronymic[con]"), _("PATRONYMIC[CON]")), 69 ("rawsurnames", "q", _("Rawsurnames"), _("RAWSURNAMES")), 70 ("notpatronymic", "o", _("Notpatronymic"),_("NOTPATRONYMIC")), 71 ("prefix", "p", _("Prefix"), _("PREFIX")), 72 ("nickname", "n", _("Nickname"), _("NICKNAME")), 73 ("familynick", "g", _("Familynick"), _("FAMILYNICK")), 74 ] 75KEY_TO_TRANS = {} 76TRANS_TO_KEY = {} 77for (key, code, standard, upper) in KEYWORDS: 78 KEY_TO_TRANS[key] = standard 79 KEY_TO_TRANS[key.upper()] = upper 80 KEY_TO_TRANS["%" + ("%s" % code)] = standard 81 KEY_TO_TRANS["%" + ("%s" % code.upper())] = upper 82 TRANS_TO_KEY[standard.lower()] = key 83 TRANS_TO_KEY[standard] = key 84 TRANS_TO_KEY[upper] = key.upper() 85 86def get_translation_from_keyword(keyword): 87 """ Return the translation of keyword """ 88 return KEY_TO_TRANS.get(keyword, keyword) 89 90def get_keyword_from_translation(word): 91 """ Return the keyword of translation """ 92 return TRANS_TO_KEY.get(word, word) 93 94def get_keywords(): 95 """ Get all keywords, longest to shortest """ 96 keys = list(KEY_TO_TRANS.keys()) 97 keys.sort(key= lambda a: len(a), reverse=True) 98 return keys 99 100def get_translations(): 101 """ Get all translations, longest to shortest """ 102 trans = list(TRANS_TO_KEY.keys()) 103 trans.sort(key= lambda a: len(a), reverse=True) 104 return trans 105