-
Notifications
You must be signed in to change notification settings - Fork 4
/
CustomTranslations.php
82 lines (67 loc) · 2.33 KB
/
CustomTranslations.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
<?php
/**
* InnoCraft - the company of the makers of Matomo Analytics, the free/libre analytics platform
*
* @link https://www.innocraft.com
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\CustomTranslations;
use Piwik\API\Request;
use Piwik\Container\StaticContainer;
use Piwik\Piwik;
use Piwik\Plugins\CustomTranslations\TranslationTypes\TranslationTypeProvider;
use Piwik\SettingsServer;
class CustomTranslations extends \Piwik\Plugin
{
public function registerEvents()
{
return array(
'API.Request.dispatch.end' => 'updateEvents',
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
);
}
public function getClientSideTranslationKeys(&$result)
{
$result[] = 'General_Language';
$result[] = 'General_Value';
$result[] = 'General_GoTo2';
$result[] = 'CustomTranslations_Translation';
$result[] = 'CustomTranslations_LanguageInlineHelp';
$result[] = 'CustomTranslations_CustomTranslations';
}
public function getStylesheetFiles(&$stylesheets)
{
$stylesheets[] = "plugins/CustomTranslations/vue/src/EditCustomTranslations/EditCustomTranslations.less";
}
public function isTrackerPlugin()
{
return false;
}
public function updateEvents(&$returnedValue, $extraInfo)
{
if (empty($extraInfo['module']) || empty($extraInfo['action'])) {
return;
}
if (SettingsServer::isTrackerApiRequest()) {
return;
}
if (SettingsServer::isArchivePhpTriggered()) {
return;
}
if (!Piwik::isUserHasSomeViewAccess()) {
return;
}
if (Request::getRootApiRequestMethod() === 'API.getSuggestedValuesForSegment') {
// we need to make sure to return the raw words here
return;
}
$module = $extraInfo['module'];
$action = $extraInfo['action'];
$method = $module . '.' . $action;
$provider = StaticContainer::get(TranslationTypeProvider::class);
foreach ($provider->getAllTranslationTypes() as $type) {
$returnedValue = $type->translate($returnedValue, $method, $extraInfo);
}
}
}