From 659c51a0110df5d6119058f559157391ee85b4e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Rapinat?= Date: Mon, 18 Jan 2010 15:46:32 +0000 Subject: [PATCH] 2384: KinshipReport use hard to translate sentences (by Josip) svn: r14094 --- src/plugins/rel/Makefile.am | 3 +- src/plugins/rel/rel_hr.py | 195 ++++++++++++++++++++++++++++++ src/plugins/rel/relplugins.gpr.py | 13 ++ 3 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 src/plugins/rel/rel_hr.py diff --git a/src/plugins/rel/Makefile.am b/src/plugins/rel/Makefile.am index 574702ecd..8236d91c5 100644 --- a/src/plugins/rel/Makefile.am +++ b/src/plugins/rel/Makefile.am @@ -13,7 +13,8 @@ pkgdata_PYTHON = \ rel_es.py\ rel_fi.py\ rel_fr.py\ - rel_hu.py\ + rel_hu.py\ + rel_hr.py\ rel_it.py\ rel_nl.py\ rel_no.py\ diff --git a/src/plugins/rel/rel_hr.py b/src/plugins/rel/rel_hr.py new file mode 100644 index 000000000..408c0fe75 --- /dev/null +++ b/src/plugins/rel/rel_hr.py @@ -0,0 +1,195 @@ +# -*- coding: utf-8 -*- +# +# Gramps - a GTK+/GNOME based genealogy program +# +# 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 +# +# +# Copyright (C) 2010 Josip (josip at pisoj dot com) + +""" +Croatian-specific classes for calculating relationships and kinship names. +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- + +#import gen.lib +import Relationship + +_PARENTS = ['', 'otac i majka', 'djedovi i bake', 'pradjedovi i prabake', + '%s pradjedovi i %s prabake'] +_CHILDS = ['', 'djeca', 'unučad', 'praunučad', '%s praunučad'] +_CHILDS_SP = ['', 'snahe i zetovi', 'prasnahe i prazetovi', + 'supružnici praunučadi', 'supružnici %s praunučadi'] + +#------------------------------------------------------------------------- +# +# Class HrDeclination +# +#------------------------------------------------------------------------- +class HrDeclination(object): + """ + Croatian declination system + """ + numdcl = { 1: 'prv', 2: 'drug', 3: 'treć', 4: 'četvrt', 5: 'pet', + 6: 'šest', 7: 'sedm', 8: 'osm', 9: 'devet', 10: 'deset', + 11: 'jedanaest', 12: 'dvanaest', 13: 'trinaest', 14: 'četrnaest', + 15: 'petnaest', 16: 'šestnaest', 17:'sedamnaest', 18: 'osamnaest', + 19: 'devetnaest', 20: 'dvadeset', 30: 'trideset', 40: 'četrdeset', + 50: 'pedeset', 60: 'šesdeset', 70: 'sedamdeset', 80: 'osamdeset', + 90: 'devedeset', + (1, 1, 1): 'i', (1, 1, 5): 'i', (1, 2, 1): 'i', (1, 2, 5): 'i', + (1, 1, 2): 'og', (1, 1, 4): 'og', (2, 1, 2): 'og', + (1, 1, 3): 'om', (1, 1, 6): 'om', (0, 1, 7): 'om', + (2, 1, 3): 'om', (2, 1, 6): 'om', (2, 2, 7): 'om', + (1, 1, 7): 'im', (2, 1, 7): 'im', (1, 2, 3): 'im', (1, 2, 6): 'im', + (1, 2, 7): 'im', (0, 2, 3): 'im', (0, 2,6): 'im', (0, 2, 7): 'im', + (0, 1, 1): 'a', (0, 1, 5): 'a', (2, 2, 1): 'a', (2, 2, 5): 'a', + (0, 1, 2): 'e', (0, 1, 4): 'e', (1, 2, 4): 'e', + (0, 2, 1): 'e', (0, 2, 4): 'e', (0, 2, 5): 'e', + (2 , 1, 1): 'o', (2, 1, 4): 'o', (2, 1, 5): 'o', + (0, 1, 3): 'oj', (0, 1, 6): 'oj', (2, 2, 3): 'oj', (2, 2, 6): 'oj', + (0, 2, 2): 'ih', (1, 2, 2): 'ih', (2, 2, 2): 'ih', + (2, 2, 4): 'u' } + + def get_ordnum(self, num, gender, number, case): + """ + Declination of ordinal numbers + gender: 0 = feminine, 1 = masculine, 2 = neuter + case: 1 = nominative, 2 = genitive, 3 = dative, 4 = accusative + 5 = vocative, 6 = locative, 7 = instrumental + number: 1 = single, 2 = plural + :rtype: str + """ + if 0 < num < 100: + lres = [] + #lres.append(self.numdcl[(num / 100) * 100]) + if (num < 21) or (num % 10) == 0: + lres.append(self.numdcl[num]) + else: + lres.append(self.numdcl[(num % 10) * 10]) + lres.append(self.numdcl[(num % 10)]) + sufix = self.numdcl[(gender, number, case)] + if num % 10 == 3: + if gender != 0 and sufix != 'oj': + sufix = sufix.replace('o','e') + lres[-1] += sufix + res = ' '.join(lres) + else: + res = str(num) + '. ' + return res + +HRD = HrDeclination() +HRDN = HRD.get_ordnum + +def _get_childs(level, inlaw): + """ children, grandchildren et. + """ + if level < len(_CHILDS)-1: + if not inlaw: + return _CHILDS[level] + else: return _CHILDS_SP[level] + else: + if not inlaw: + return '%s' % _CHILDS[4] % (HRDN(level-2, 0, 1, 1)) + elif inlaw: + return '%s' % _CHILDS_SP[4] % (HRDN(level-2, 0, 2, 1)) + +def _get_parents(level): + """ parents, grandparents + """ + if level < 4: + return _PARENTS[level] + else: + return u'%s' % _PARENTS[4] % (HRDN(level-2, 1, 1, 1), + HRDN(level-2, 0, 2, 1)) + +def _get_uncles(gen, inlaw): + """ in general: uncles, ants--- + """ + if gen == 2: + if not inlaw: + return 'stričevi, ujaci i tetke' + else: + return 'strine, ujne i tetci' + elif gen == 3: + if not inlaw: + return 'prastričevi, praujaci i pratetke' + else: + return 'prastrine, praujne i pratetci' + else: + if not inlaw: + return '%s prastričevi, %s praujaci i %s pratetke' % (HRDN(gen-2, + 1, 2, 1), HRDN(gen-2, 1, 2, 1), HRDN(gen-2, 0, 2, 1)) + else: + return 'prastrine, praujne i pratetci' + +#------------------------------------------------------------------------- +# +# CroatianRelationshipCalculator +# +#------------------------------------------------------------------------- + +class RelationshipCalculator(Relationship.RelationshipCalculator): + """ + RelationshipCalculator Class + """ + def __init__(self): + Relationship.RelationshipCalculator.__init__(self) + + def get_plural_relationship_string(self, gena, genb, reltocommon_a='', + reltocommon_b='', only_birth=True, in_law_a=False, in_law_b=False): + """returns kinship terms for groups of persons + """ + if not in_law_b: + rel_str = u'potomci %s generacije predaka u %s koljenu: '\ + % (HRDN(gena, 0, 1, 2), HRDN(genb, 2, 1, 6)) + elif in_law_b: + rel_str = u'supružnici potomaka %s generacije predaka u %s '\ + 'koljenu: ' % (HRDN(gena, 0, 1, 2), HRDN(genb, 2, 1, 6)) + if genb == 0: + #These are ancestors + rel_str = u'%s generacija predaka: %s' % (HRDN(gena, + 0, 1, 1),_get_parents(gena)) + elif gena == 0: + # These are descendants + if not in_law_b: + rel_str = u'%s generacija potomaka: %s' % (HRDN(genb, + 0, 1, 1), _get_childs(genb, in_law_b)) + else: rel_str = u'supružnici %s generacije potomaka: %s' \ + % (HRDN(genb, 0, 2, 1), _get_childs(genb, in_law_b)) + elif gena == 1 == genb: + # These are siblings + if not in_law_b: + rel_str += u'braća i sestre' + else: rel_str = u'supružnici braće i sestara' + elif genb == 1: + # These are aunts/uncles + rel_str += _get_uncles(gena, in_law_b) + return rel_str + +if __name__ == "__main__": + + # Test function. Call it as follows from the command line (so as to find + # imported modules): + # export PYTHONPATH=/path/to/gramps/src + # python src/plugins/rel/rel_ru.py + from Relationship import test + RC = RelationshipCalculator() + test(RC, True) diff --git a/src/plugins/rel/relplugins.gpr.py b/src/plugins/rel/relplugins.gpr.py index dcc05cfba..0886be3c7 100644 --- a/src/plugins/rel/relplugins.gpr.py +++ b/src/plugins/rel/relplugins.gpr.py @@ -111,6 +111,19 @@ plg.lang_list = ["fr", "FR", "fr_FR", "fr_CA", "francais", "fr_FR.UTF-8", "fr_FR.utf-8", "fr_FR.utf8", "fr_CA.UTF-8"] +# hr +plg = newplugin() +plg.id = 'relcalc_hr' +plg.name = _("Croatian Relationship Calculator") +plg.description = _("Calculates relationships between people") +plg.version = '1.0' +plg.status = STABLE +plg.fname = 'rel_hr.py' +plg.ptype = RELCALC +plg.relcalcclass = 'RelationshipCalculator' +plg.lang_list = ["hrvatski", "Hrvatski", "croatian", "Croatian", + "hr", "HR", "hr_HR", "hr_HR.UTF-8", "hr_HR.utf-8"] + # hu plg = newplugin() plg.id = 'relcalc_hu'