-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathps_translateyourmodule.php
executable file
·193 lines (175 loc) · 5.33 KB
/
ps_translateyourmodule.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_')) {
exit;
}
require_once __DIR__ . '/vendor/autoload.php';
class ps_translateyourmodule extends Module
{
const DEFAULT_LANGUAGE_ISO = 'en';
const AJAX_CONTROLLER_NAME = 'AdminAjaxPsTranslateYourModule';
const MIME_TYPE_EXPECTED_XLSX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
const EXPECTED_EXTENSION = '.xlsx';
const FORM_ERROR_CODES = [
'modulename' => 0,
'ziperror' => 1,
'translation' => 2,
];
public $name;
public $tab;
public $version;
public $author;
public $module_key;
public $author_address;
public $bootstrap;
public $displayName;
public $description;
protected $css_path;
protected $js_path;
protected $img_path;
protected $modulePageConfiguration;
/**
* __construct
*
* @return void
*/
public function __construct()
{
$this->name = 'ps_translateyourmodule';
$this->tab = 'other';
$this->version = '1.5.0';
$this->author = 'PrestaShop';
$this->module_key = '';
$this->author_address = '';
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Translate your module');
$this->description = $this->l('It allow to export all the sentences needed to be translated and to import it');
$this->css_path = $this->_path . 'views/css/';
$this->js_path = $this->_path . 'views/js/';
$this->img_path = $this->_path . 'views/img/';
$this->setControllers();
}
/**
* Loads asset resources
*
* @return void
*/
public function loadAsset()
{
Media::addJsDef([
'ajax_controller_url' => $this->context->link->getAdminLink(self::AJAX_CONTROLLER_NAME),
'ajax_controller_name' => self::AJAX_CONTROLLER_NAME,
'mimetype_xlsx' => self::MIME_TYPE_EXPECTED_XLSX,
]);
$jsFile = [
$this->js_path . 'admin/general.js',
$this->js_path . 'admin/loadDropZone.js',
$this->js_path . 'admin/dropzone.min.js',
];
$cssFile = [
$this->css_path . 'admin/general.css',
$this->css_path . 'admin/versions/17_style.css',
$this->css_path . 'admin/dropzone.css',
];
$this->context->controller->addJS($jsFile);
$this->context->controller->addCSS($cssFile, 'all');
}
/**
* Admin module content
*
* @return string
*/
public function getContent()
{
$this->loadAsset();
$this->context->smarty->assign([
'modulesFoldersPath' => _MODULE_DIR_,
'imagePath' => $this->img_path,
'languagesList' => \Language::getLanguages(),
'moduleList' => array_reverse(\Module::getModulesInstalled()),
'loadExportLink' => $this->context->link->getAdminLink('AdminExportTranslations', true, [], ['export_type' => 'load']) . '&module_name=',
'emptyExportLink' => $this->context->link->getAdminLink('AdminExportTranslations', true, [], ['export_type' => 'empty']) . '&module_name=',
'downloadTranslationsZip' => $this->context->link->getAdminLink('AdminDownloadZip') . '&module_name=',
'postError' => Tools::getValue('error_controller', false),
]);
return $this->display(__FILE__, 'views/templates/admin/configure.tpl');
}
/**
* Get module page configuration with errors if there is
*
* @param array $error
*
* @return string
*/
public function getModulePageConfiguration(array $error = [])
{
$parameters = array_merge(
['configure' => $this->name],
$error
);
return $this->context->link->getAdminLink(
'AdminModules',
true,
[],
$parameters
);
}
/**
* Install the module
*
* @return bool
*/
public function install()
{
return parent::install();
}
/**
* Uninstall the module
*
* @return bool
*/
public function uninstall()
{
return parent::uninstall();
}
/**
* setControllers
*
* @return void
*/
public function setControllers()
{
$this->controllers = [
self::AJAX_CONTROLLER_NAME,
'AdminExportTranslations',
'AdminDownloadZip',
];
}
/**
* getControllers
*
* @return array
*/
public function getControllers()
{
return $this->controllers;
}
}