Difference between revisions of "Specification:Relationship Calculator"
(conversion of relationshipcalculator) |
m (→How to write a relationship calculator: correct API links) |
||
Line 13: | Line 13: | ||
==How to write a relationship calculator== | ==How to write a relationship calculator== | ||
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 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:// | + | # 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/devdoc/api/2.2/private/GrampsDb._GrampsDbBase.GrampsDbBase-class.html GrampsDbBase] instance as its argument and that has a <code>get_relationship</code> method obeying the following rules: |
− | #* The arguments of <code>get_relationship</code> method are two [http:// | + | #* The arguments of <code>get_relationship</code> method are two [http://www.gramps-project.org/devdoc/api/2.2/private/RelLib._Person.Person-class.html Person] objects. To be determined is the relationship of the second person to the first person. |
#* The values returned by the function are the string of the relationship (e.g. "father", or "grandson") and the list of the closest common ancestors of these two persons. | #* The values returned by the function are the string of the relationship (e.g. "father", or "grandson") and the list of the closest common ancestors of these two persons. | ||
#* For the sake of the following example, assume that the above function is defined in <code>src/plugins/rel_xx.py</code> (where <code>xx</code> is your language code), and it's name is <code>get_relationship(first_person,second_person)</code>. Also assume that it returns a pair of values: <code>(rel_string, acnestor_list)</code>. | #* For the sake of the following example, assume that the above function is defined in <code>src/plugins/rel_xx.py</code> (where <code>xx</code> is your language code), and it's name is <code>get_relationship(first_person,second_person)</code>. Also assume that it returns a pair of values: <code>(rel_string, acnestor_list)</code>. |
Revision as of 19:23, 7 March 2007
This article provides the rationale and requirements for the Relationship Calculator plugin for GRAMPS, and it's localisation.
Why have different relationship calculators?
Different cultures and regions tend to view relationships in different ways. In the United States (and probably other English speaking regions), you can encounter a third cousin, twice removed, which in other regions is meaningless. Other cultures have different terms for your mother's grandfather and your father's grandfather, while English speaking regions would refer to both as a great-grandfather.
By providing relationship calculators, several problems are resolved.
- Meaningful relation descriptions are returned localized for the user's region.
- The relationship calculator plugin can return the relationship outside of the Relationship Calculator, allowing relationships to be used in reports and other areas.
- 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
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
rel
plugins) must define a class that can be instantiated with the GrampsDbBase instance as its argument and that has aget_relationship
method obeying the following rules:- The arguments of
get_relationship
method are two Person objects. To be determined is the relationship of the second person to the first person. - The values returned by the function are the string of the relationship (e.g. "father", or "grandson") and the list of the closest common ancestors of these two persons.
- For the sake of the following example, assume that the above function is defined in
src/plugins/rel_xx.py
(wherexx
is your language code), and it's name isget_relationship(first_person,second_person)
. Also assume that it returns a pair of values:(rel_string, acnestor_list)
. - 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 arguments of
- The
rel
plugin must register itself with the plugins system as therelcalc
tool. This is done by inserting the following code at the end of yourrel_xx.py
plugin:
from PluginMgr import register_relcalc register_relcalc(RelationshipCalculatorClass,["xx","XX", "xx_YY","xxxxxx","Xxxxxx","Xxxxxxx_xx"])
- where
RelationshipCalculatorClass
is the class whose method is theget_relationship
and the items in quotes are language identifiers that may possibly be associated with your language. For example, different systems useru
,RU
,ru_RU
,koi8r
,ru_koi8r
,russian
,Russian
,ru_RU.koi8r
, etc. to identify the Russian language.
That's it for the requirements. The example relcalc
plugins can be found in src/Relationship.py
and src/plugins/rel_ru.py
.