forked from hartenthaler/hh_relation_is_descriptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRelationIsDescriptorAddon.php
246 lines (219 loc) · 7.19 KB
/
RelationIsDescriptorAddon.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?php
/**
* RelationIsDescriptorAddon: custom module to add more relation descriptors
*
* webtrees: online genealogy
* Copyright (C) 2021 Hermann Hartenthaler
* Copyright (C) 2021 webtrees development team
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Hartenthaler\Webtrees\Module\RelationIsDescriptorAddon;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Tree;
/**
* Class RelationIsDescriptorAddon
*
* provides additional custom relation descriptors
*
* A word or phrase with size=1:25 that states object 1's relation is object 2.
* For example, you would read the following as
* "Joe Jacob's great-grandson is the submitter pointed to by the XREF @S1@":
* 0 INDI
* 1 NAME Joe /Jacob/
* 1 ASSO @S1@
* 2 RELA great-grandson
*/
class RelationIsDescriptorAddon implements ModuleCustomInterface
{
use ModuleCustomTrait;
// List of const for module administration
public const CUSTOM_TITLE = 'Custom Relation Descriptors';
public const CUSTOM_DESCRIPTION = 'Provide additional relation descriptors';
public const CUSTOM_MODULE = 'hh_relation_is_descriptor';
public const CUSTOM_AUTHOR = 'Hermann Hartenthaler';
public const CUSTOM_GITHUB = 'https://github.com/hartenthaler/';
public const CUSTOM_WEBSITE = self::CUSTOM_GITHUB . self::CUSTOM_MODULE . '/';
public const CUSTOM_VERSION = '2.1.1.0';
public const CUSTOM_LAST = self::CUSTOM_WEBSITE . 'raw/main/latest-version.txt';
/**
* How should this module be identified in the control panel, etc.?
*
* @return string
*/
public function title(): string
{
/* I18N: Name of a module */
return I18N::translate(self::CUSTOM_TITLE);
}
/**
* A sentence describing what this module does.
*
* @return string
*/
public function description(): string
{
/* I18N: Description of the module */
return I18N::translate(self::CUSTOM_DESCRIPTION);
}
/**
* The version of this module.
*
* @return string
*/
public function customModuleVersion(): string
{
return self::CUSTOM_VERSION;
}
/**
* A URL that will provide the latest version of this module.
*
* @return string
*/
public function customModuleLatestVersion(): string
{
return self::CUSTOM_LAST;
}
/**
* A URL that will provide the latest version of this module.
*
* @return string
*/
public function customModuleLatestVersionUrl(): string
{
return self::CUSTOM_LAST;
}
/**
* Where to get support for this module? Perhaps a GitHub repository?
*
* @return string
*/
public function customModuleSupportUrl(): string
{
return self::CUSTOM_WEBSITE;
}
/**
* The person or organisation who created this module.
*
* @return string
*/
public function customModuleAuthorName(): string
{
return self::CUSTOM_AUTHOR;
}
/**
* Should this module be enabled when it is first installed?
*
* @return bool
*/
public function isEnabledByDefault(): bool
{
return true;
}
public function accessLevel(Tree $tree, string $interface): int
{
return 0;
// TODO: Implement accessLevel() method.
}
public function setEnabled(bool $enabled): \Fisharebest\Webtrees\Module\ModuleInterface
{
// TODO: Implement setEnabled() method.
return $this;
}
public function setName(string $name): void
{
// TODO: Implement setName() method.
}
public function isEnabled(): bool
{
// TODO: Implement isEnabled() method.
return true;
}
public function setPreference(string $setting_name, string $setting_value): void
{
// TODO: Implement setPreference() method.
}
public function getPreference(string $setting_name, string $default = ''): string
{
// TODO: Implement getPreference() method.
return 'pref';
}
public function name(): string
{
// TODO: Implement name() method.
return 'name';
}
public function resourcesFolder(): string
{
// TODO: Implement resourcesFolder() method.
return '';
}
public function boot(): void
{
$ef = Registry::elementFactory();
$ef->registerTags(['INDI:ASSO:RELA' => new ExtendedRelationIsDescriptor(I18N::translate('Relationship'))]);
$ef->registerTags(['INDI:*:ASSO:RELA' => new ExtendedRelationIsDescriptor(I18N::translate('Relationship'))]);
$ef->registerTags(['INDI:*:_ASSO:RELA' => new ExtendedRelationIsDescriptor(I18N::translate('Relationship'))]);
$ef->registerTags(['FAM:*:_ASSO:RELA' => new ExtendedRelationIsDescriptor(I18N::translate('Relationship'))]);
}
/**
* Additional translations.
*
* @param string $language
* @return array<string,string>
*/
public function customTranslations(string $language): array
{
switch ($language) {
case 'de':
return $this->germanTranslations();
case 'nl':
return $this->dutchTranslations();
default:
return [];
}
}
/**
* @return array<string,string>
*/
private function germanTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
// tbd how to translate context sensitive?
return [
'Custom Relation Descriptors' => 'Kundenindividuelle Beziehungsbezeichnungen',
'Provide additional relation descriptors' => 'Bereitstellen von zusätzlichen Beziehungsbezeichnungen',
'Landlord' => 'Vermieter',
'Landlord (male)' => 'Vermieter',
'Landlord (female)' => 'Vermieterin',
];
}
/**
* @return array<string,string>
*/
private function dutchTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
// tbd how to translate context sensitive?
return [
'Custom Relation Descriptors' => 'Aangepaste relatiebeschrijvingen',
'Provide additional relation descriptors' => 'Stel aanvullende relatiebenamingen beschikbaar',
'Guru' => 'Goeroe',
'Landlord' => 'Huisbaas',
'Landlord (male)' => 'Huisbaas',
'Landlord (female)' => 'Hospita',
];
}
}