-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExampleModule.php
155 lines (138 loc) · 4.63 KB
/
ExampleModule.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
<?php
/**
* Example module.
*/
declare(strict_types=1);
namespace ExampleNamespace;
use Fisharebest\Localization\Translation;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Module\AbstractModule;
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
/**
* Class ExampleModule
*
* This example shows how to create a custom module.
* All the functions are optional. Just implement the ones you need.
*
* Modules *must* implement ModuleCustomInterface. They *may* also implement other interfaces.
*/
class ExampleModule extends AbstractModule implements ModuleCustomInterface
{
// For every module interface that is implemented, the corresponding trait *should* also use be used.
use ModuleCustomTrait;
/**
* The constructor is called on all modules, even ones that are disabled.
* Note that you cannot rely on other modules (such as languages) here, as they may not yet exist.
*
*/
public function __construct()
{
}
/**
* Bootstrap. This function is called on *enabled* modules.
* It is a good place to register routes and views.
* Note that it is only called on genealogy pages - not on admin pages.
*
* @return void
*/
public function boot(): void
{
}
/**
* How should this module be identified in the control panel, etc.?
*
* @return string
*/
public function title(): string
{
return I18N::translate('Example module');
}
/**
* A sentence describing what this module does.
*
* @return string
*/
public function description(): string
{
return I18N::translate('This module does not do anything');
}
/**
* The person or organisation who created this module.
*
* @return string
*/
public function customModuleAuthorName(): string
{
return 'Greg Roach';
}
/**
* The version of this module.
*
* @return string
*/
public function customModuleVersion(): string
{
return '1.0.0';
}
/**
* A URL that will provide the latest version of this module.
*
* @return string
*/
public function customModuleLatestVersionUrl(): string
{
return 'https://github.com/webtrees/example-module/raw/main/latest-version.txt';
}
/**
* Where to get support for this module. Perhaps a github repository?
*
* @return string
*/
public function customModuleSupportUrl(): string
{
return 'https://github.com/webtrees/example-module';
}
/**
* Additional/updated translations.
*
* @param string $language
*
* @return array<string>
*/
public function customTranslations(string $language): array
{
switch ($language) {
case 'en-AU':
case 'en-GB':
case 'en-US':
// Note the special characters used in plural and context-sensitive translations.
return [
'Individual' => 'Fish',
'Individuals' => 'Fishes',
'%s individual' . I18N::PLURAL . '%s individuals' => '%s fish' . I18N::PLURAL . '%s fishes',
'Unknown given name' . I18N::CONTEXT . '…' => '?fish?',
'Unknown surname' . I18N::CONTEXT . '…' => '?FISH?',
];
case 'fr':
case 'fr-CA':
return [
// These are new translations:
'Example module' => 'Exemple module',
'This module does not do anything' => 'Ce module ne fait rien',
// These are updates to existing translations:
'Individual' => 'Poisson',
'Individuals' => 'Poissons',
'%s individual' . I18N::PLURAL . '%s individuals' => '%s poisson' . I18N::PLURAL . '%s poissons',
'Unknown given name' . I18N::CONTEXT . '…' => '?poission?',
'Unknown surname' . I18N::CONTEXT . '…' => '?POISSON?',
];
case 'some-other-language':
// Arrays are preferred, and are faster.
// If your module uses .MO files, then you can convert them to arrays like this.
return (new Translation('path/to/file.mo'))->asArray();
default:
return [];
}
}
}