1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Example module. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace MyCustomNamespace; |
10
|
|
|
|
11
|
|
|
use Fisharebest\Localization\Translation; |
12
|
|
|
use Fisharebest\Webtrees\I18N; |
13
|
|
|
use Fisharebest\Webtrees\Module\AbstractModule; |
14
|
|
|
use Fisharebest\Webtrees\Module\ModuleCustomInterface; |
15
|
|
|
use Fisharebest\Webtrees\Module\ModuleCustomTrait; |
16
|
|
|
|
17
|
|
|
return new class extends AbstractModule implements ModuleCustomInterface { |
18
|
|
|
use ModuleCustomTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Constructor. The constructor is called on *all* modules, even ones that are disabled. |
22
|
|
|
* This is a good place to load business logic ("services"). Type-hint the parameters and |
23
|
|
|
* they will be injected automatically. |
24
|
|
|
*/ |
25
|
|
|
public function __construct() |
26
|
|
|
{ |
27
|
|
|
// NOTE: If your module is dependent on any of the business logic ("services"), |
28
|
|
|
// then you would type-hint them in the constructor and let webtrees inject them |
29
|
|
|
// for you. However, we can't use dependency injection on anonymous classes like |
30
|
|
|
// this one. For an example of this, see the example-server-configuration module. |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Bootstrap. This function is called on *enabled* modules. |
35
|
|
|
* It is a good place to register routes and views. |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
public function boot(): void |
40
|
|
|
{ |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* How should this module be identified in the control panel, etc.? |
45
|
|
|
* |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
|
|
public function title(): string |
49
|
|
|
{ |
50
|
|
|
return 'My custom module'; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* A sentence describing what this module does. |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function description(): string |
59
|
|
|
{ |
60
|
|
|
return 'This module doesn‘t do anything'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* The person or organisation who created this module. |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function customModuleAuthorName(): string |
69
|
|
|
{ |
70
|
|
|
return 'Greg Roach'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* The version of this module. |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function customModuleVersion(): string |
79
|
|
|
{ |
80
|
|
|
return '1.0.0'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* A URL that will provide the latest version of this module. |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function customModuleLatestVersionUrl(): string |
89
|
|
|
{ |
90
|
|
|
return 'https://www.example.com/latest-version.txt'; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Where to get support for this module. Perhaps a github respository? |
95
|
|
|
* |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function customModuleSupportUrl(): string |
99
|
|
|
{ |
100
|
|
|
return 'https://www.example.com/support'; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Additional/updated translations. |
105
|
|
|
* |
106
|
|
|
* @param string $language |
107
|
|
|
* |
108
|
|
|
* @return string[] |
109
|
|
|
*/ |
110
|
|
|
public function customTranslations(string $language): array |
111
|
|
|
{ |
112
|
|
|
switch ($language) { |
113
|
|
|
case 'en-AU': |
114
|
|
|
case 'en-GB': |
115
|
|
|
case 'en-US': |
116
|
|
|
return $this->englishTranslations(); |
117
|
|
|
|
118
|
|
|
case 'fr': |
119
|
|
|
case 'fr-CA': |
120
|
|
|
return $this->frenchTranslations(); |
121
|
|
|
|
122
|
|
|
case 'some-other-language': |
123
|
|
|
// Arrays are preferred, and faster. |
124
|
|
|
// If your module uses .MO files, then you can convert them to arrays like this. |
125
|
|
|
return (new Translation('path/to/file.mo'))->asArray(); |
126
|
|
|
|
127
|
|
|
default: |
128
|
|
|
return []; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return array |
134
|
|
|
*/ |
135
|
|
|
protected function englishTranslations(): array |
136
|
|
|
{ |
137
|
|
|
// Note the special characters used in plural and context-sensitive translations. |
138
|
|
|
return [ |
139
|
|
|
'Individual' => 'Fish', |
140
|
|
|
'Individuals' => 'Fishes', |
141
|
|
|
'%s individual' . I18N::PLURAL . '%s individuals' => '%s fish' . I18N::PLURAL . '%s fishes', |
142
|
|
|
'Unknown given name' . I18N::CONTEXT . '…' => '?fish?', |
143
|
|
|
'Unknown surname' . I18N::CONTEXT . '…' => '?FISH?', |
144
|
|
|
]; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return array |
149
|
|
|
*/ |
150
|
|
|
protected function frenchTranslations(): array |
151
|
|
|
{ |
152
|
|
|
return [ |
153
|
|
|
'Individual' => 'Poisson', |
154
|
|
|
'Individuals' => 'Poissons', |
155
|
|
|
'%s individual' . I18N::PLURAL . '%s individuals' => '%s poisson' . I18N::PLURAL . '%s poissons', |
156
|
|
|
'Unknown given name' . I18N::CONTEXT . '…' => '?poission?', |
157
|
|
|
'Unknown surname' . I18N::CONTEXT . '…' => '?POISSON?', |
158
|
|
|
]; |
159
|
|
|
} |
160
|
|
|
}; |
161
|
|
|
|