Changes

Jump to: navigation, search

Specification:Relationship Calculator

3,385 bytes added, 16:24, 1 September 2019
m
linked to intro to Relationship Calculator
Rationale and requirements for the [[Gramps_5.1_Wiki_Manual_-_Tools#Relationship_Calculator|Relationship Calculator ]] plugin for GRAMPSGramps, and it's localisationits localization.
==Why have different relationship calculators?==
* Translators do not have to worry about trying to translate strings such as "third cousin twice removed" into a local phrase that has no equivalent.
==How to write a relationship calculator for =====For Gramps 4.x.x===The relationship calculator Logic is the same as Gramps version 3.0. Only paths and filename etc have been updated due to the Code reorganisation. Here are the rules the language-specific plugins must obey to be compatible with the [https://gramps-project.org/docs/relationship.html framework]:# You need to make localized versions of the methods::#get_single_relationship_string (used on ''quick report''):#get_sibling_relationship_string (used on ''RelCalc'' tool and on ''Status Bar''):#get_plural_relationship_string (used on ''kinship report''):#get_partner_relationship_string - only make a localized version of this if the gettext translation present in Relationship.py is not sufficient :Note that the signature of the methods must be identical to the ones in [{{Code Base}}gramps/gen/relationship.py gramps/gen/relationship.py] All other methods are unique to the English module, and should not be overwritten. You can however define your own helper functions like present in relationship.py, eg _get_father(). Helper functions start with a _ and are not used outside of the Relationship class module. Text strings returned by the function should be in the UNICODE character set. GNOME expects all displayed strings to be UNICODE characters, and most report formats use UNICODE. While it may be tempting to use ISO-8859 or other character sets, these will not display correctly and will cause errors. The relationship plugin must be [[GEPS 014: Plugin registration and management|registered]] in the plugin system. In short, you have to edit the file <code>[{{Code Base}}gramps/plugins/rel/relplugins.gpr.py relplugins.gpr.py]</code> in the directory <code>gramps/tree/master/gramps/plugins/rel</code>. Follow the model of any of the other languages, and fill in all the possible language identifiers that '''may possibly''' be associated with your language: for example, different systems use <code>ru</code>, <code>RU</code>, <code>ru_RU</code>, <code>koi8r</code>, <code>ru_koi8r</code>, <code>russian</code>, <code>Russian</code>, <code>ru_RU.koi8r</code>, etc. to identify the Russian language. That's it for the requirements. The example <code>relcalc</code> plugins can be found in <code>[{{Code Base}}gramps/gen/relationship.py gramps/gen/relationship.py]</code> and <code>[{{Code Base}}/gramps/plugins/rel/rel_it.py gramps/plugins/rel/rel_it.py]</code> or <code>[{{Code Base}}gramps/plugins/rel/rel_nl.py gramps/plugins/rel/rel_nl.py]</code>. ====Tests==== You are further strongly advised to run the same tests as are present at the bottom of those files. If you have obtained Gramps Git in <code>/home/me/Gramps</code>, then you can run the test for eg. rel_it.py as follows in a terminal:  cd /home/me/Gramps export PYTHONPATH=/home/me/Gramps/gramps python gramps/plugins/rel/rel_it.py You could also run [[Programming_Guidelines#Pylint|pylint]] as follows in a terminal cd /home/me/Gramps export PYTHONPATH=/home/me/Gramps/gramps pylint gramps/plugins/rel/rel_it.py > /home/me/Gramps/gramps/plugins/rel/it.txt ===For Gramps 3.x.x===
The relationship calculator changed for version 3.0. Logic has been separated from translation, which will allow code improvements to occur more easily, being available immediately in all translated modules.
Here are the rules the language-specific plugins must obey to be compatible with the [http://www.gramps-project.org/docs/relationship.html framework]:
# You need to make localized versions of the methods:
:#get_single_relationship_string(used on ''quick report''):#get_sibling_relationship_string(used on ''RelCalc'' tool and on ''Status Bar''):#get_plural_relationship_string (used on ''kinship report'')
:#get_partner_relationship_string - only make a localized version of this if the gettext translation present in Relationship.py is not sufficient
:#get_grandparents_string
:Note that the signature of the methods must be identical to the ones in Relationship.py
All other methods are unique to the English module, and should not be overwritten. You can however define your own helper functions like present in Relationship.py, eg _get_father(). Helper functions start with a _ and are not used outside of the Relationship class module.
# Text strings returned by the function should be in the UNICODE character set. GNOME expects all displayed strings to be UNICODE characters, and most report formats use UNICODE. While it may be tempting to use ISO-8859 or other character sets, these will not display correctly and will cause errors.# The relationship plugin must register itself with be [[GEPS 014: Plugin registration and management|registered]] in the plugin system as . In short, you have to edit the file <code>relcalcrelplugins.gpr.py</code> tool. This is done by inserting in the following directory <code at >src/plugins/rel</code>. Follow the end model of any of the other languages, and fill in all the possible language identifiers that '''may possibly''' be associated with your language: for example, different systems use <code>ru</code>rel_xx, <code>RU</code>, <code>ru_RU</code>, <code>koi8r</code>, <code>ru_koi8r</code>, <code>russian</code>, <code>Russian</code>, <code>ru_RU.pykoi8r</code> file:, etc. to identify the Russian language.
from PluginMgr import register_relcalc register_relcalc(RelationshipCalculatorClass,["xx","XX","xx_YY","xxxxxx","Xxxxxx","Xxxxxxx_xx"])That's it for the requirements. The example <code>relcalc</code> plugins can be found in <code>src/Relationship.py</code> and <code>src/plugins/rel/rel_it.py</code> or <code>src/plugins/rel/rel_nl.py</code>.
:where <code>RelationshipCalculatorClass</code> is the class you defined inheriting from Relationship.RelationshipCalculator, and the items in quotes are language identifiers that '''may possibly''' be associated with your language. For example, different systems use <code>ru</code>, <code>RU</code>, <code>ru_RU</code>, <code>koi8r</code>, <code>ru_koi8r</code>, <code>russian</code>, <code>Russian</code>, <code>ru_RU.koi8r</code>, etc. to identify the Russian language.====Tests====
That's it for You are further strongly adviced to run the same tests as are present at the requirementsbottom of those files. The example <code>relcalc</code> plugins can be found If you have obtained Gramps Git in <code>src/Relationship.py</code> and <code>srchome/pluginsme/rel_it.pyGramps</code> or <code>src/plugins/rel_nl, then you can run the test for eg. rel_it.py</code>.as follows in a terminal:
You are further strongly adviced to run the same tests as are present at the bottom of those files. If you have obtained GRAMPS svn in <code> cd /home/me/Gramps export PYTHONPATH=/home/me/grampssvn<Gramps/src python src/plugins/rel/code>, then you can run the test for eg. rel_it.py as follows in a terminal:
You could also run [[Programming_Guidelines#Pylint|pylint]] as follows in a terminal cd /home/me/grampssvnGramps export PYTHONPATH=/home/me/grampssvnGramps/src python pylint src/plugins/rel/rel_it.py> /home/me/Gramps/src/plugins/rel/it.txt
==How to write a relationship calculator in =For Gramps 2.2.x===
The framework for relationship calculator plugins is in place. Here are the rules the language-specific plugins must obey to be compatible with the framework:
# The relationship plugins (here and below referred to as <code>rel</code> plugins) must define a class that can be instantiated with the [http://www.gramps-project.org/devdocdocs/apigen/2gen_db.2/private/GrampsDbhtml#module-gen._GrampsDbBasedb.GrampsDbBase-class.html base GrampsDbBase] instance as its argument and that has a <code>get_relationship()</code> method obeying the following specifications:#* The <code>get_relationship()</code> method takes '''two''' input arguments, which are two instances of the [http://www.gramps-project.org/devdocdocs/apigen/2gen_lib.2/private/RelLib._Personhtml#module-gen.Person-classlib.html person Person] class. To be determined is the relationship of the second person to the first person.
#* The <code>get_relationship()</code> method returns a tuple with '''two''' values:
#*# The string of the relationship (e.g. "father", or "grandson")
That's it for the requirements. The example <code>relcalc</code> plugins can be found in <code>src/Relationship.py</code> and <code>src/plugins/rel_ru.py</code>.
 
==See also==
*[[Handler List]]
*[[Calendar tools holidays]]
[[Category:Translators/Categories]]
[[Category:Developers/General]]
[[Category:Plugins]]
[[Category:Tools]]
[[Category:GEPS|C]]
4,529
edits

Navigation menu