-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultLanguageMiddleware.php
108 lines (93 loc) · 2.9 KB
/
DefaultLanguageMiddleware.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
<?php
/**
* An custom module to force the primary language as default,
* indepent from the browser language tag..
*/
declare(strict_types=1);
namespace DefaultLanguageMiddlewareNamespace;
use Fisharebest\Localization\Locale;
use Fisharebest\Localization\Locale\LocaleInterface;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Module\AbstractModule;
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
use Fisharebest\Webtrees\Module\ModuleLanguageInterface;
use Fisharebest\Webtrees\Session;
use Fisharebest\Webtrees\Site;
use Fisharebest\Webtrees\View;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use function in_array;
class DefaultLanguageMiddleware extends AbstractModule implements ModuleCustomInterface, MiddlewareInterface {
use ModuleCustomTrait;
/**
* How should this module be identified in the control panel, etc.?
*
* @return string
*/
public function title(): string
{
return I18N::translate('Default Language');
}
/**
* {@inheritDoc}
* @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName()
*/
public function customModuleAuthorName(): string
{
return 'Lars van Ravenzwaaij';
}
/**
* {@inheritDoc}
* @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
*/
public function customModuleVersion(): string
{
return '1.0.0';
}
/**
* {@inheritDoc}
* @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleLatestVersionUrl()
*/
public function customModuleLatestVersionUrl(): string
{
return 'https://raw.githubusercontent.com/LarsRabe/MyDefaultLanguage/refs/heads/main/latest-version.txt';
}
/**
* {@inheritDoc}
* @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl()
*/
public function customModuleSupportUrl(): string
{
return 'https://github.com/LarsRabe/DefaultLanguageMiddleware';
}
/**
* Additional translations.
*
* @param string $language
*
* @return array<string>
*/
public function customTranslations(string $language): array
{
switch ($language) {
case 'nl':
return [
'Default Language' => 'Standaardtaal',
];
default:
return [];
}
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (Session::get('language') !== 'nl') {
I18N::init('nl');
Session::put('language', 'nl');
}
// Generate the response
return $handler->handle($request);
}
}