1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* webtrees-mod-translationtool: MyArtJaub Translation Tool Module for webtrees |
5
|
|
|
* |
6
|
|
|
* @package MyArtJaub\Webtrees\Module |
7
|
|
|
* @subpackage TranslationTool |
8
|
|
|
* @author Jonathan Jaubart <[email protected]> |
9
|
|
|
* @copyright Copyright (c) 2020, Jonathan Jaubart |
10
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
declare(strict_types=1); |
14
|
|
|
|
15
|
|
|
namespace MyArtJaub\Webtrees\Module\TranslationTool\Http\RequestHandlers; |
16
|
|
|
|
17
|
|
|
use Fisharebest\Webtrees\I18N; |
18
|
|
|
use Fisharebest\Webtrees\Exceptions\HttpNotFoundException; |
19
|
|
|
use Fisharebest\Webtrees\Http\ViewResponseTrait; |
20
|
|
|
use Fisharebest\Webtrees\Services\ModuleService; |
21
|
|
|
use MyArtJaub\Webtrees\Module\TranslationTool\TranslationToolModule; |
22
|
|
|
use MyArtJaub\Webtrees\Module\TranslationTool\Model\TranslationsAnalyzer; |
23
|
|
|
use MyArtJaub\Webtrees\Module\TranslationTool\Services\SourceCodeService; |
24
|
|
|
use Psr\Http\Message\ResponseInterface; |
25
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
26
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Request handler for displaying the status of translations in MyArtJaub modules |
30
|
|
|
*/ |
31
|
|
|
class TranslationStatus implements RequestHandlerInterface |
32
|
|
|
{ |
33
|
|
|
use ViewResponseTrait; |
34
|
|
|
|
35
|
|
|
/** @var TranslationToolModule $module */ |
36
|
|
|
private $module; |
37
|
|
|
|
38
|
|
|
/** @var SourceCodeService $sourcecode_service */ |
39
|
|
|
private $sourcecode_service; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Constructor for TranslationStatus request handler |
43
|
|
|
* |
44
|
|
|
* @param ModuleService $module_service |
45
|
|
|
* @param SourceCodeService $sourcecode_service |
46
|
|
|
*/ |
47
|
|
|
public function __construct(ModuleService $module_service, SourceCodeService $sourcecode_service) |
48
|
|
|
{ |
49
|
|
|
$this->module = $module_service->findByInterface(TranslationToolModule::class)->first(); |
50
|
|
|
$this->sourcecode_service = $sourcecode_service; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritDoc} |
55
|
|
|
* @see \Psr\Http\Server\RequestHandlerInterface::handle() |
56
|
|
|
*/ |
57
|
|
|
public function handle(ServerRequestInterface $request): ResponseInterface |
58
|
|
|
{ |
59
|
|
|
$this->layout = 'layouts/administration'; |
60
|
|
|
|
61
|
|
|
if ($this->module === null) { |
62
|
|
|
throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$locale = I18N::locale(); |
66
|
|
|
$sourceCodePaths = $this->sourcecode_service->sourceCodePaths(); |
67
|
|
|
$translation_analyser = new TranslationsAnalyzer( |
68
|
|
|
$this->sourcecode_service, |
69
|
|
|
$sourceCodePaths, |
70
|
|
|
$locale->languageTag() |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
return $this->viewResponse($this->module->name() . '::status', [ |
74
|
|
|
'title' => $this->module->title(), |
75
|
|
|
'language' => $locale->endonym(), |
76
|
|
|
'source_code_paths' => $sourceCodePaths->flatten()->sort(), |
77
|
|
|
'translations_stats' => $translation_analyser->translationsStatictics(), |
78
|
|
|
'missing_translations' => $translation_analyser->missingTranslations(), |
79
|
|
|
'non_used_translations' => $translation_analyser->nonUsedMajTranslations() |
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|