forked from pkp/translator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TranslatorPlugin.inc.php
151 lines (134 loc) · 4.31 KB
/
TranslatorPlugin.inc.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
<?php
/**
* @file plugins/generic/translator/TranslatorPlugin.inc.php
*
* Copyright (c) 2014-2018 Simon Fraser University
* Copyright (c) 2003-2018 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class TranslatorPlugin
* @ingroup plugins_generic_translator
*
* @brief This plugin helps with translation maintenance.
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class TranslatorPlugin extends GenericPlugin {
/**
* Register the plugin
* @param $category string Plugin category
* @param $path string Plugin path
* @return boolean True on success
*/
function register($category, $path) {
if (parent::register($category, $path)) {
if ($this->getEnabled()) {
// Allow the Translate tab to appear on website settings
HookRegistry::register('Templates::Management::Settings::website', array($this, 'callbackShowWebsiteSettingsTabs'));
// Register the components this plugin implements to
// permit administration of static pages.
HookRegistry::register('LoadComponentHandler', array($this, 'setupComponentHandlers'));
// Bring in the TranslatorAction helper class.
$this->import('TranslatorAction');
}
return true;
}
return false;
}
/**
* Extend the website settings tabs to include translation
* @param $hookName string The name of the invoked hook
* @param $args array Hook parameters
* @return boolean Hook handling status
*/
function callbackShowWebsiteSettingsTabs($hookName, $args) {
$output =& $args[2];
$request = Registry::get('request');
$dispatcher = $request->getDispatcher();
// Add a new tab for static pages
$output .= '<li><a name="translate" href="' . $dispatcher->url($request, ROUTE_COMPONENT, null, 'plugins.generic.translator.controllers.grid.LocaleGridHandler', 'index') . '">' . __('plugins.generic.translator.translate') . '</a></li>';
// Permit other plugins to continue interacting with this hook
return false;
}
/**
* Permit requests to the static pages grid handler
* @param $hookName string The name of the hook being invoked
* @param $args array The parameters to the invoked hook
*/
function setupComponentHandlers($hookName, $params) {
$component =& $params[0];
switch ($component) {
case 'plugins.generic.translator.controllers.grid.LocaleGridHandler':
case 'plugins.generic.translator.controllers.grid.LocaleFileGridHandler':
case 'plugins.generic.translator.controllers.grid.MiscTranslationFileGridHandler':
case 'plugins.generic.translator.controllers.grid.EmailGridHandler':
case 'plugins.generic.translator.controllers.listbuilder.LocaleFileListbuilderHandler':
// Allow the static page grid handler to get the plugin object
import($component);
$className = array_pop(explode('.', $component));
$className::setPlugin($this);
return true;
}
return false;
}
/**
* @copydoc Plugin::getDisplayName()
*/
function getDisplayName() {
return __('plugins.generic.translator.name');
}
/**
* @copydoc Plugin::getDescription()
*/
function getDescription() {
return __('plugins.generic.translator.description');
}
/**
* @copydoc Plugin::isSitePlugin()
*/
function isSitePlugin() {
return true;
}
/**
* @copydoc Plugin::getActions()
*/
function getActions($request, $actionArgs) {
$dispatcher = $request->getDispatcher();
import('lib.pkp.classes.linkAction.request.RedirectAction');
return array_merge(
$this->getEnabled() && Validation::isSiteAdmin()?array(
new LinkAction(
'translate',
new RedirectAction($dispatcher->url(
$request, ROUTE_PAGE,
null, 'management', 'settings', 'website',
array('uid' => uniqid()), // Force reload
'translate' // Anchor for tab
)),
__('plugins.generic.translator.translate'),
null
)
):array(),
parent::getActions($request, $actionArgs)
);
}
/**
* Get the JavaScript URL for this plugin.
*/
function getJavaScriptURL($request) {
return $request->getBaseUrl() . '/' . $this->getPluginPath() . '/js';
}
/**
* @copydoc PKPPlugin::getTemplatePath
*/
function getTemplatePath($inCore = false) {
return parent::getTemplatePath($inCore) . 'templates/';
}
/**
* Get the registry path for this plugin.
* @return string Registry path
*/
function getRegistryPath() {
return parent::getPluginPath() . '/registry';
}
}
?>